创建Mysql数据库的连接

先创建一个java类UserMysql:

public class UserMysql {
	private static String url="jdbc:mysql://localhost:3306/‘数据库名’";
	private static String username="用户名";
	private static String password="用户密码";
	
	private static Connection connection=null;
	
	public static Connection getConnectionInstance() throws ClassNotFoundException, SQLException {
		
		if(null==connection) {
			Class.forName("com.mysql.jdbc.Driver");
			connection=DriverManager.getConnection(url,username,password);
			return connection;
		}else {
			return connection;
		}
	}
}

mysql架包下载地址:http://archive.apache.org/dist/commons/dbcp/binaries/
https://dev.mysql.com/downloads/connector/

猜你喜欢

转载自blog.csdn.net/wufewu/article/details/83175860