Lead Jar Pack (copy sticker)
Then configure the build path
Find the jar package in the project
Load Driver
Public classDbutil {Private Static FinalString dbdriver = "Com.mysql.jdbc.Driver"; Private Static FinalString Dburl = "Jdbc:mysql://127.0.0.1:3306/emp_dept"; Private Static FinalString USER = "root"; Private Static FinalString PASSWORD = "123456"; Public Static voidMain (string[] args)throwsException {//load the database driver Class.forNameClass.forName (Dbdriver);
Connecting to a database
The connection data must depend on the DriverManager class to complete
Private Static Final String Dburl = "Jdbc:mysql://127.0.0.1:3306/emp_dept";// jdbc database native Name table name private Static Final String USER = "root"; User name privatestaticfinal String PASSWORD = "123"; Password
DriverManager method getconnection, return connection; in JDBK, each database connection is to use a connection package, so as long as the occurrence of connection, it means to link the database;
Connection conn = drivermanager.getconnection (Dburl, USER, PASSWORD);
Verify that there is no connection, just see that Conn is not NULL, it represents the connection
SYSTEM.OUT.PRINTLN (conn);
Already connected
Close the database
Conn.close ();
Java Connection MySQL Database