JDBC connection mysql

xiaoxiao2021-03-06  42

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)

The test code is as follows:

<% @ Page ContentType = "Text / HTML; Charset = GB2312"%> <% @ page language = "java" import = "java.sql. *"%> <% string mysqldriver = "org.gjt.mm.mysql .Driver "; striver"; String Url = "jdbc: mysql: // localhost / test"; // Database connection connection conn; class.forname (mysqldriver); conn = drivermanager.getConnection (URL, "root", "cleverSoft"); // Username and password IF (conn == null) {system.out.println ("get conn error");} Statement Stmt = conn.createstatement (); ResultSet RS = NULL; RS = Stmt.executeQuery ("SELECT * from newTable "); while (rs.next ()) {// loop display record%> ID: <% = rs.getstring (" id ")%> Name1: <% = rs.getstring (" name1 ") %> Name2: ("Name2")%>) <% = "
"%> <%} rs.close (); stmt.close (); conn.Close (); %>

转载请注明原文地址:https://www.9cbs.com/read-57728.html

New Post(0)