Import the Mysql-connector-java-5.1.6-bin.jar into the Tomcat Lib directory.
In a Java project, you just need to introduce Mysql-connector-java-5.1.6-bin.jar to run a Java project.
In a Web project, when Class.forName ("Com.mysql.jdbc.Driver"), MyEclipse is not going to find the string and will not look for the driver. So just copy the Mysql-connector-java-5.1.6-bin.jar to the Tomcat under the Lib directory.
Import in JSP pages
<% @page import= "Java.sql.SQLException"%>
<% @page import= "Java.sql.Connection"%>
<% @page import= "Java.sql.DriverManager"%>
<% @page import= "Java.sql.Driver"%>
Connecting to a database
<%
try{
Class.forName ("Com.mysql.jdbc.Driver");
}catch (Exception e) {
E.printstacktrace ();
}
try {
Connection connection=drivermanager.getconnection ("Jdbc:mysql://localhost:3306/test", "root", "123456");
OUT.PRINTLN ("Database connection succeeded!");
Connection.close ();
} catch (Exception e) {
OUT.PRINTLN ("Database connection failed");
}
%>
Java Web JSP connection MySQL Database