数据库01(验证连接是否成功)
package org.lxh.demo17.connectdemo;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class ConnectionDemo02 {
public static final String DBDRIVER = "com.mysql.jdbc.Driver";
public static final String DBURL = "jdbc:mysql://localhost:3306/mldn";
public static final String DBUSER = "root";
public static final String DBPASS = "xyzk123";
public static void main(String[] args) {
Connection conn = null;
try{
Class.forName(DBDRIVER);
}catch(ClassNotFoundException e){
e.printStackTrace();
}
try{
conn = DriverManager.getConnection(DBURL, DBUSER, DBPASS);
}catch(SQLException e){
e.printStackTrace();
}
System.out.println(conn);
try{
conn.close();
}catch(SQLException e){
e.printStackTrace();
}
}
}