forked from JustinSDK/JavaSE6Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResultDemo.java
More file actions
58 lines (53 loc) · 1.77 KB
/
ResultDemo.java
File metadata and controls
58 lines (53 loc) · 1.77 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package onlyfun.caterpillar;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class ResultDemo {
public static void main(String[] args) {
DBSource dbsource = null;
Connection conn = null;
Statement stmt = null;
try {
dbsource = new SimpleDBSource();
conn = dbsource.getConnection();
stmt = conn.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
ResultSet result = stmt.executeQuery(
"SELECT * FROM t_message");
result.afterLast();
while(result.previous()) {
System.out.print(result.getInt("id") + "\t");
System.out.print(result.getString("name") + "\t");
System.out.print(result.getString("email") + "\t");
System.out.println(result.getString("msg"));
}
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
finally {
if(stmt != null) {
try {
stmt.close();
}
catch(SQLException e) {
e.printStackTrace();
}
}
if(conn != null) {
try {
dbsource.closeConnection(conn);
}
catch(SQLException e) {
e.printStackTrace();
}
}
}
}
}