JSP connection MySQL Database method
First copy the MySQL database connection driver to the Tomcat/common/lib package
Download Mysql-connector-java-5.1.6.zip
Http://mysql.cs.pu.edu.tw/Downloads/Connector-J/mysql-connector-java-5.1.6.zip
Configure Tomcat's virtual directory-slightly
Create a jdbcmysql.jsp page
The page code is as follows:
Copy Code code as follows:
<%@ page contenttype= "text/html;charset=gb2312"%>
<%@ page import= "java.sql.*"%>
<%
Final String mysqldbdriver= "Org.gjt.mm.mysql.Driver";
Final String mysqldburl= "JDBC:MYSQL://LOCALHOST/MLDN";
Final String mysqldbuser= "root";
Final String mysqldbuserpass= "root";
Connection con = null;
%>
<%
try{
Class.forName (Mysqldbdriver);
con = drivermanager.getconnection (mysqldburl,mysqldbuser,mysqldbuserpass);
Statement stmt = Con.createstatement ();
String sql = "CREATE table jobs (name varchar (32))";
Execute CREATE statement
Stmt.executeupdate (SQL);
OUT.PRINTLN ("Connection successful!") ");
Stmt.close ();
}catch (Exception e) {
Out.println (e);
}
%>
Start Tomcat
Address bar Input: http://localhost:8080/Demo/jdbcMySql.jsp
Test Data Connection Success!
Validating the database
Verify success!
-----The way to connect Ms SQL Server/oracle