package com.jdbcbiancheng.exp01;
import java.sql.Connection;
import java.sql.DriverManager;
public class DbUtil {
private String dburl="jdbc:mysql://localhost;3306/db_book";
private String dbUsername="root";
private String dbPassword="123456";
private String jdbcName="com.mysql.jdbc.Driver";
/**
* 获取数据库连接
* @return
* @throws Exception
*/
public Connection getCon()throws Exception{
Class.forName(jdbcName);
Connection con = DriverManager.getConnection(dburl, dbUsername, dbPassword);
return con;
}
/**
* ]关闭数据库连接
* @param con
* @throws Exception
*/
public void closeCon(Connection con) throws Exception{
if(con!=null){
con.close();
}
}
}