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 that the installation path is d: /java/jdk1.5.0_01 Set the 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 the first installed JDK5.0 path is not automatically identified during installation, 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 to D: / Tomcat 5.5 / conf / Catalina / LocalHost new Test.xml content is as follows:
D: / WWW path will be the root of our test website
After restarting the Tomcat service, visit http:// localhost: 8080 / test in the browser
3. Install mysql4.1.8
Download: http://dev.mysql.com/downloads/index.html
Install to D: / MySQL, create a new DB for TEST
4. Install JDBC Drive Mysql Connector / J 3.1.6
Download: http://dev.mysql.com/downloads/index.html
After decompression, copy the mysql-connection-java-3.1.6-bin.jar to D: / Tomcat 5.5 / Common / LIB or D: /JAVA/JDK1.5.0_01/jre/lib/ext or elsewhere (then Need to set ClassPath points to this path)
5. Create a new TEST.JSP
Save to D: / WWW
The content is as follows: <% @ Page ContentType = "text / html; charset = GB2312"%> <% @ page import = "java.sql. *"%> <%
STATEMENT STMT = NULL; ResultSet RS = 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");