-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConnDB.java
More file actions
29 lines (25 loc) · 732 Bytes
/
Copy pathConnDB.java
File metadata and controls
29 lines (25 loc) · 732 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
package xwq;
import java.sql.*;
public class ConnDB {
/**
* @param args
*/
public static void main(String[] args) throws SQLException, Exception{
try{
Class.forName("com.ibm.db2.jcc.DB2Driver").newInstance();
String url = "jdbc:db2://192.168.1.106:50000/sample";
String user = "db2inst1";
String password = "Db2";
Connection conn = DriverManager.getConnection(url, user, password);
System.out.println("Connection Done!");
Statement stmt = conn.createStatement();
String sql = "select * from act";
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()){
System.out.println(rs.getString(1) + " " + rs.getString(2));
}
}catch(SQLException e){
System.out.println(e);
}
}
}