最简单的JDBC连接

public class DBHelper {
	private static String url = "jdbc:mysql://localhost:3306/employeedb";
	private static String userName = "root";
	private static String passWord = "root";
	private static Connection conn = null;
	
	
	private DBHelper(){
		
	}
	
	public static Connection getConnection(){
		if(null == conn){
			try {
				Class.forName("com.mysql.jdbc.Driver");
				conn = DriverManager.getConnection(url, userName, passWord);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
		return conn;
	}
}

你可能感兴趣的:(学习笔记)