In the previous article, tofu once talked about a JDBC-ODBC Bridge to connect to the database article a connection to the database javaBean (can be called in Jsp ), since the efficiency of connecting to the database is very low, we actually use JDBC in actual use, now I will explain how to use JDBC to connect to MySql in Win2K.
The first is mySQL JDBC driver download, in: http://download.sourceforge.net/pub/mirrors/mysql/Downloads/Contrib/mm.mysql.jdbc-1.2c.tar.gz
After the download is complete, decompress the zip file to any directory. Assume that the directory is d: \ jdbc, OK! Next we will set ClassPAth to ensure that our WebServer can access this driver.
The setting method is as follows:
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: \ jdbc \ mm. mysql. jdbc-1.2c \ mysql_comp.jar
3. Restart the server
Wait until the startup is complete.
After the JDBC settings are complete, many people may not know whether our JDBC installation is successful, we will use a JDBC connection MySQl program to check whether the installation is successful. The Code is as follows:
<% @ Page contentType = "text/html; charset = gb2312" %>
<%
Java. SQL. Connection conn;
Java. lang. String strConn;
Class. forName ("org. gjt. mm. mysql. Driver"). newInstance ();
SqlConn = java. SQL. DriverManager. getConnection ("jdbc: mysql: // localhost/test", "root ","");
%>
Although the code is simple, we have completed the test of MySql JDBC installation.
Thanks to the help of the Oriental snake, I would like to express my gratitude for the completion of this article.
/*
Tofu is made of excellent products
Http://www.asp888.net bean curd technology station
If reprinted, Please retain the complete copyright information
*/