1. Add the driver files to the app project
By copying the driver Mysql-connector-java-5.1.6-bin to the Web application's Web-inf\lib, the Web application can access the MySQL database through the JDBC interface.
2. Load register the specified database driver
For MySQL database, its driver loading format:
Class.forName ("Com.mysql.jdbc.Driver");
JDBC Connection Database Create connection object
First form ' Connect symbol word (URL) ', then use "connection symbol word" to implement the connection and create the Connection object
1. URL of the database connection
String URL 1= "Jdbc:mysql:";
String ur2= "? user=root&password= password";
String ur3= "&useunicode=true&characterencoding=utf-8";
String Url=url1+url2+url3;
2. Connect using the connection symbol Word to get the connection object
A static Connection getconnection (String URL)
B static Connection getconnection (String url,properties info);
C static Connection getconnection (String url,string user,string password):
3. Use JDBC to connect MySQL database, get common format of connection object
Example
Assuming that the MySQL database is "Students", the user name of the database operation is "root", the password is "123456", the code is "Utf-8"
String drivername= "Com.mysql.jdbc.driver";
String username= "Root"
String userpwd= "123456"
String dbname= "Students"
String ur1= "jdbc:mysql;//localhost:3306/" =dbname;
String ur2= "? user=" = "usernanme" = "&password=" =USERPWD;
String url3= "&useunicode=true&characterencoding=utf-8";
String Url=url1+url2+url3
Class.forName (drivername);
Connection conn=drivermanager.getconnection (URL);
Registering drivers that drive MySQL