In fact, I personally think that Applet To access the database, I use my previous article "Servlet Transfer Query Collection to Applet" to implement better, so you don't have to download the JDBC driver without the client, and you don't have to expose the database structure. So this article is only a technical discussion. I have to explain this is an instance of the applet directly accesses the SQLServer2000. I think other databases is similar. Ready to work, download Microsoft SQL Server 2000 Driver for JDBC to Microsoft Site. The following detailed explanation: 1. Write a simple appletimport java.Awt. *; Import java.applet. *; Import java.sql. *;
public class Test extends Applet {private String strErrorMessage = ""; public void init () {try {// Register SQLServer2000 jdbc driver Class.forName ( "com.microsoft.jdbc.sqlserver.SQLServerDriver"); // Connection database connection conn = DriverManager.getConnection ( "jdbc: microsoft: sqlserver: //192.9.200.52: 1433; databaseName = bluesite", "sa", ""); String sql = "SELECT UserName FROM UserInfo"; Statement stmt = conn.createStatement (); ResultSet RSLT = Stmt.executeQuery (SQL); while (rslt.next ()) {strerrorMessage =}} rslt.close (); stmt.close (); conn.Close () ;} CatCH (Exception Exp) {strerrorMessage = Exp.toString ();}}
Public Void Paint (Graphics G) {g.drawstring (StrerrorMessage, 50, 60);}} compiled.
2. Built a Test.jar with Test.class, Solving Test.class, and SQLSERVER2000 drivers to pack it in. The final Test.jar directory structure is as follows: com / microsoft / jdbc [directory] COM / Microsoft / JDBCX [directory] COM / Microsoft / Util [directory] TEST.CLASS
3. Write a HTML file
head>