Tutorial on helping customers (www.bkjia.com)The first step to connect to MySQL using JDBC code in JSP web page is the download of the JDBC driver, in: http://download.sourceforge.net/pub/mirrors/mysql/Downloads/Contrib/mm.mysql.jdbc-1.2c.tar.gz
After the JDBC driver is downloaded, decompress the zip file to any directory. Assume that the directory is d: jdbc, OK! The following describes how to set ClassPAth to ensure that our WebServer can access this driver:
1. Choose my computer> system> set the environment variable. Edit the variable if ClassPAth already exists. Otherwise, add a ClassPAth.
2. Set the value of ClassPAth: d: jdbcmm. mysql. jdbc-1.2cmysql_comp.jar
3. after the server is restarted, after the JDBC settings are complete, many people may not know whether our JDBC installation is successful, we will use a JDBC connection to MySQL to check whether the installation is successful.
The JDBC code in the JSP webpage is as follows:
- <% @ Page contentType = "text/html; charset = gb2312" %>
- <% Java. SQL. Connection conn;
- Java. lang. String strConn; Class. forName ("org. gjt. mm. MySQL (the best combination with PHP). Driver"). newInstance ();
- SqlConn = java. SQL. DriverManager. getConnection ("jdbc: MySQL (the best combination with PHP): // localhost/test", "root", ""); %>
Copy code |