gteric 发表于 2016-11-13 01:05:36

db2 jdbgc连接

import java.sql.*;

public class DBUtil {

static String userName = "test";
static String password = "Admin@123";
static String url = "jdbc:db2://127.0.0.1:50000/testdb";

public static Connection getConn() {
Connection con = null;
try {
                            //直接连接db2数据库
Class.forName("com.ibm.db2.jcc.DB2Driver");
con = DriverManager.getConnection(url, userName, password);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return con;

}

public static void main(String[] args) {
Connection conn = getConn();
try {
ResultSet set = conn.createStatement().executeQuery("select * from test_t1 ");
while (set.next()) {
System.out.println(set.getInt(1));
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
页: [1]
查看完整版本: db2 jdbgc连接