import java.sql.*;
public class DBConn2 {
public static void main(String[] args) {
try {
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Success loading JDBC-ODBC Bridge Driver");
} catch (ClassNotFoundException e){
System.out.println("JDBC 沒有驅動程式" + e.getMessage());
}
try {
String url = "jdbc:mysql://localhost:3306/phone?" +
"user=root&password=12345";
Connection conn = DriverManager.getConnection(url);
if(!conn.isClosed())
System.out.println("資料庫連線成功");
conn.close();
}
catch(SQLException e) {
System.out.println("資料庫連線失敗");
}
}
}
執行結果
沒有留言:
張貼留言