forked from JustinSDK/JavaSE6Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnectionDemo.java
More file actions
32 lines (25 loc) · 883 Bytes
/
ConnectionDemo.java
File metadata and controls
32 lines (25 loc) · 883 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package onlyfun.caterpillar;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
public class ConnectionDemo {
public static void main(String[] args) {
try {
DBSource dbsource = new SimpleDBSource();
Connection conn = dbsource.getConnection();
if(!conn.isClosed()) {
System.out.println("資料庫連線已開啟…");
}
dbsource.closeConnection(conn);
if(conn.isClosed()) {
System.out.println("資料庫連線已關閉…");
}
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
}