Set up a database
1. Click Connect-->mysql: Enter the connection name, hostname/ IP address, port, user name, password (omitted without password), then click OK, the established table is gray to indicate off state, double click to open
2. re-create a database
Right-click the table--New database--fill in the database name, set to UTF8, collation can not write, default is the first:utf8-general-ci
Connect to a database using pure code
Steps:
< Span style= "font-family: the song Body;" >1. Load MySQL driver:
The default is to load the JVM (Java Virtual machine) driver, call the static method Class.forName (String name) for the Java.lang.class class to achieve
2. Connect the database statement:
You need to send a Java.sql.DriverManager request to get the Connection object :drivermanager. getconnection(String URL, Properties info)
parameter URL: Protocol: Sub-Protocol: Data source identification; Where the protocol is JDBC, the sub-protocol is the MySQL database management name, the data source ID is your IP or port number
Parameter Info: usually contains user name and password
3. Close Resources
Public classTest { Public Static voidMain (string[] args) {//TODO auto-generated Method Stub//1. Load the database driver Try{class.forname ("Com.mysql.jdbc.Driver"); } Catch(ClassNotFoundException e) {//TODO auto-generated Catch blockE.printstacktrace (); } //2. Establish a connection to get the connection objectConnection conn =NULL; Try {
Conn= Drivermanager.getconnection ("Jdbc:mysql:///epet", "root", "root"); System.out.println ("Connection succeeded");
} Catch(SQLException e) {//TODO auto-generated Catch blockE.printstacktrace (); } //3. Close Resources Try{conn.close (); } Catch(SQLException e) {//TODO auto-generated Catch blockE.printstacktrace (); } }}
Using Java-only code to make MySQL connections