In the previous write application, I have experienced successful experience through JDBC. Can I connect MYSQL through the same code in a web page written in JSP? The result is negative, when I copied the same code to the file, an error occurs. So Baidu sent a trip to find a related article. After research, it is actually just a change. Change the original driver manager to: class.forname ("org.gjt.mm.mysql.driver); the following code can be used as a reference:
Try {Connection Connect = DriverManager.getConnection ("JDBC: MySQL: // LocalHost / JDBCTEST", "UserID", "Password"); Out.print ("Success Connect MySQL Server!");
Statement Stmt = Connect.createStatement (); ResultSet RS = Stmt.executeQuery ("SELECT * FROM EMPLOYEES"); while (rs.next ()) {Out.Println (rs.getint (1)); Out.Println (RS .getstring (2)); OUT.PRINTLN (Rs.Getint (3)); Out.Println (Rs.Getint (4));
}}}} Catch (exception e) {Out.print ("get Data Error!"); E.PrintStackTrace ();}%>
body> html> Note: MySQL's JDBC driver download can refer to my previous article to copy the JAR file to common / lib under the Tomcat installation directory (I use Tomcat server, other types of other types I didn't work on the server).