MySQL driver: mysql-connection-java-3.1.7.tar.gzj2se version: 1.5.0_02tomcat version: 5.0.30Mysql: 4.1.10 or 3.23.49 (I used)
First, decompress the MySQL driver, there is a MySQL-Connector-Java-3.1.7-bin.jar package under /mysql-connector-java-3.1.7. Copy it to
Java installation directory D: / program / javad: / program files / java / jre1.5.0_02 / lib / ext (debugging Java program) and D: / Program files / java / jdk1.5.0_02 / jre / lib / EXT (using the Tomcat program, you can also copy to% catalina% / common / lib)
Another way is to find a directory to store MySQL driver. Add the path to the path in the environment variable.
A Java Application example.
// loadDriverimport java.sql.connection; import java.sql.driverManager; import java.sql.sqlexception; // notice, do not import com.mysql.jdbc. * // or you will have problems!
Public class loaddriver {public static void main (string [] args) {Try {// the newinstance () call is a work aroundancy some // broken java importation
Class.Forname ("com.mysql.jdbc.driver). Newinstance ();} catch (exception ex) {system.out.println (ex);}}}
After debugging, running loadDriver.class If there is no abnormality, the driver configuration of the JavaAplication program is successful.
A JSP example
<% @ Page ContentType = "Text / HTML; Charset = GB2312"%> <% @ Page Import = "Java.SQL. *"%>
<% connection con; statement sql; resultet ket; {Class.Forname ("com.mysql.jdbc.driver). Newinstance ();} catch (classnotfoundexception e) {E.getMessage ();} try {con = drivermanager.getConnection (" JDBC: mysql: // localhost / mysql? user = & password = & useunicode = true & characterencoding = GBK ");SQL = con.createstatement (); rs = sql.executeQuery ("Select * from user"); out.print ("