Mysql--連接數據庫

在javaEE中連接mysql數據庫:

Mysql:   

    String Driver="com.mysql.jdbc.Driver";    //驅動程序
    String URL="jdbc:mysql://localhost:3306/db_name";  //連接的URL,db_name數據庫名  

    String Username="username";    //用戶名

    String Password="password";   //密碼
    Class.forName(Driver).new Instance();
    Connection con
=
DriverManager.getConnection(URL,Username,Password);
例如:

    Class.forName(com.mysql.jdbc.Driver);

    Connection con=DriverManager.getConnection     ("jdbc:mysql://localhost:3306/bookstore","root","root");//bookstore爲數據庫名, root root爲用戶名和密碼

    

發佈了14 篇原創文章 · 獲贊 5 · 訪問量 12萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章