[java]代码库
package com.course.DAL;
import java.sql.Connection;
import java.sql.DriverManager;
import com.course.UTIL.Alert;
public class DbUtil {
	public Connection getCon() throws Exception
	{
		String driver="com.mysql.jdbc.Driver";
		String url="jdbc:mysql://localhost:3306/test?useSSL=false";
		String usn="root";
		String pwd="root";
		
		Class.forName(driver);
		Connection conn = DriverManager.getConnection(url,usn,pwd);
		return conn;
	}
public void getClose (Connection conn) throws Exception
{
	if(conn!=null)
		conn.close();
	
}
}
//public static void main(String[] args) {
//	DbUtil dbUtil= new DbUtil();
//	Connection conn=null;
//	try {
//		conn=dbUtil.getCon();
//		Alert.show("数据库连接成功!");
//	}
//	catch (Exception e) {
//		e.printStackTrace();
//		Alert.show("数据库连接失败!");
//	}
//	finally {
//		try {
//			dbUtil.getClose(conn);
//		}
//			catch(Exception e) {
//				e.printStackTrace();
//			}
//	}
//}
//}