JSP connection database --- mysql Time: 2005-1-24 Operating System: Windows XP SP1 1. Install JDK 5.0 Update 1 Download: http://java.sun.com/ Assume the installation path to D: / Java / JDK1. 5.0_01 Set an environment variable (Control Panel -> System -> Advanced) Java_Home = D: /JAVA/JDK1.5.0_01classpath = .; D: /JAVA/JDK1.5.0_01/lib/dt.jar; D: / Java / JDK1.5.0_01 / lib / Tools.jar; Path = path;% java_home% / bin 2. Install Tomcat 5.5.4 Download: http://jakarta.apache.org/site/binindex.cgi (http: // Apache .freeelamp.com / jakarta / tomcat-5 / v5.5.4 / bin / jakarta-tomcat-5.5.4.exe) Install to D: / Tomcat 5.5, install Tomcat 5.5 requires JRE 5.0, if there is no automatic identification during installation A installed JDK5.0 path, you need to manually specify the path to JRE5.0. Set the environment variable CATALINA_HOME = D: / Tomcat 5.5 Add a virtual directory Test in Tomcat, D: / Tomcat 5.5 / Conf / Catalina / Localhost The new Test.xml is as follows: context> D: / www The path will be the root of our test website in the browser via http: // localhost: 8080 / test access 3. Install mysql4.1.8 Download: http: //dev.mysql.com/downloads/index.html Install to D : / Mysql, newly built DB 4. Install JDBC Drive Mysql Connector / J 3.1.6 Download: http://dev.mysql.com/downloads/index.html After decompression, Mysql-Connector-Java -3.1.6-bin.jar Copy to D: / Tomcat 5.5 / Common / LIB Or d: /java/jdk1.5.0_01/jre/lib/ext or elsewhere (you need to set the classpath point to the path) 5. New Test.jsp Save to D: / WWW content as follows: <% @ Page ContentType = "Text / html; charset = GB2312"%> <% @ page import = "java.sql. *"%> <% statement stmt = null; resultset = null; class.forname ("com.mysql.jdbc.driver ") .newInstance (); try {Connection conn = DriverManager.getConnection (" jdbc: mysql:? // localhost / test user = root & password = sea1980 "); stmt = conn.createStatement (); rs = stmt.executeQuery (" Select * from test "); while (rs.next ()) {%> Your first field content is: <% = rs.getstring (1)%> <