public Connection getConnection(){ Connection conn=null; try { //加载MySQL数据库驱动 Class.forName("com.mysql.jdbc.Driver"); System.out.println("数据库驱动加载成功!!"); //定义连接数据库的url String url="jdbc:mysql://localhost:3306/db_database17"; //定义连接数据库的用户名 String user="root"; //定义连接数据库的密码 String passWord="111"; conn=DriverManager.getConnection(url,user,passWord); System.out.println("已成功地与MySQL数据库建立连接!!"); } catch (ClassNotFoundException | SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return conn; }
【MySQL】JDBC连接MySQL数据库
猜你喜欢
转载自blog.csdn.net/hutuyaoniexi/article/details/80630771
今日推荐
周排行