package com.ddChat.utils;
import java.sql.Connection;
import java.sql.DriverManager;
public class DbUtil
{
public DbUtil()
{
super();
// TODO Auto-generated constructor stub
}
private String dbURL = "jdbc:mysql://localhost:3306/dd";
private String dbUserName = "root";
private String dbPassword = "fang";
private String jdbcName = "com.mysql.jdbc.Driver";
public Connection getCon() throws Exception
{
Class.forName(jdbcName);
Connection con = DriverManager.getConnection(dbURL,dbUserName,dbPassword);
return con;
}
public void closeCon(Connection con) throws Exception
{
if(con != null)
{
con.close();
}
}
public static void main(String[] args) {
DbUtil dbUtil=new DbUtil();
try {
dbUtil.getCon();
System.out.println("数据库连接成功");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
阅读(1664) | 评论(0) | 转发(0) |