import java.sql.*;
public class DBConnectionDemo {
public static void main(String[] args) {
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/My108";
String user = "root";
String password = "1234";
Connection conn = null;
Statement stmt = null;
try {
Class.forName(driver);
conn = DriverManager.getConnection(url,user, password);
if(conn != null && !conn.isClosed()) {
System.out.println("資料庫連線測試成功!");
}
}
catch(ClassNotFoundException e) {
System.out.println("找不到驅動程式類別");
e.printStackTrace();
}
catch(SQLException e) {
e.printStackTrace();
}finally{
try{
if(stmt!=null){stmt.close();}
if(conn!=null){conn.close();}
}catch(SQLException e){
System.err.println(e);
}
}
}
}
標籤
Android
(
1
)
DbVisualizer
(
2
)
html/javascript
(
1
)
java
(
11
)
MySQL
(
1
)
oracle
(
1
)
servlet&jsp
(
3
)
struts
(
2
)
沒有留言 :
張貼留言