美文网首页
Jdbc连接MySQL数据库

Jdbc连接MySQL数据库

作者: 朱燊 | 来源:发表于2017-05-05 02:45 被阅读0次

String driver = "com.mysql.jdbc.Driver";

String url= "jdbc:mysql://127.0.0.1:3306/zhushen";

String user = "root";

String password = "Code531182";

try {

Class.forName(driver);

}catch(ClassNotFoundException e) {

System.out.println("Sorry,can`t find the Driver!");

}

try{

Connection conn=DriverManager.getConnection(url1,user,password);//开始连接

if(!conn.isClosed())

System.out.println("Succeeded connecting to the Database!");

}catch(Exception e){

e.printStackTrace();

}

相关文章

网友评论

      本文标题:Jdbc连接MySQL数据库

      本文链接:https://www.haomeiwen.com/subject/pxljtxtx.html