Not much to say, the configuration steps are as follows: 1. Install JDK and perform environment variable configuration; 2. Install Tomcat and perform environment variable configuration: classpath = d: /j2sdk1.4.2_05/lib/dt.jar; D: / J2SDK1 .4.2_05 / lib / Tools.jar; D: /J2SDK1.4.2_05/bin; d: /mysql_jdbc/mysql-connector-java-3.0.15-ga-bin.jar; D: / mysql_jdbc / lib .; java_home = D: /J2SDK1.4.2_05 Tomcat_Home = D: /jakarta-Tomcat-4.1.30 3. Install MySQL and perform environment variable configuration; start the mysql server; 4. Download the mysql_jdbc, download URL: http: // dev. mysql.com/get/downloads/connector-j/mysql-connector-java-3.0.15-ga.zip/from/pick 5. Decompression and copy mysql-connector-java-3.0.15-ga-bin.jar To Tomcat Installation Directory / CommMon / lib / 6. Writing .jsp code: The code is as follows:
<% @ page import = "java.sql.connection"%> <% @ page import = "java.sql.driverManager"%> <% @ page import = "java.sql.sqlexception"%>%>
<% @ Page ContentType = "text / html; charset = GB2312"%>
<% Try {
Class.Forname ("com.mysql.jdbc.driver). NewInstance ();} catch (exception ex) {out.println (" Error " EX);} try {connection conn = drivermanager.getConnection (" JDBC: MySQL: // localhost / family? user = root & password = admin "); if (! conn.isclosed ()) Out.print (" successfully connected to the database! "); conn.close ();} catch (SQLException EX) {
Out.println ("SQLException:" ex.getMessage ()); out.println ("SqlState:" ex.getsqlstate ()); Out.println ("vendorerror:" ex.GeterrorCode ());}
%> center> body> html> Ok: Try, Windows2000 Server J2SDK1.4.2_05