数据库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();
    }
  }
}

posted @ 2017-06-19 21:38  XuGuobao  阅读(447)  评论(0编辑  收藏  举报