📄 db2populator.java
字号:
package com.darkblue.db;
import java.sql.*;
public class DB2Populator {
public static void main(String args[]) {
Connection con = null;
Statement stmt = null;
String sql = null;
ResultSet rs = null;
sql = "select firstnme,lastname,salary from employee where salary > 20000 order by salary";
// Set JDBC URL in a variable
//String url = "jdbc:db2:EASTWIND";//type 2
//String url = "jdbc:db2://192.168.70.94:6789/EASTWIND"; //type 3
String url = "jdbc:db2://192.168.70.94:50000/EASTWIND"; //type 4
String userName = "administrator";
String password = "admin";
for (int k = 0; k < 1; k++) {
try {
//Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");//type2,needclient
//Class.forName("COM.ibm.db2.jdbc.net.DB2Driver"); //type3
Class.forName("com.ibm.db2.jcc.DB2Driver");//type4 !DB2 Charset
System.out.println("DriverManager.getConnection");
con = DriverManager.getConnection(url, userName, password);
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
} catch (SQLException e2) {
e2.printStackTrace();
}
try {
stmt = con.createStatement();
rs = stmt.executeQuery(sql);
// Retrieve the result from ResultSet and display it
while (rs.next()) {
String firstname = rs.getString(1);
String dname = rs.getString(2);
double salary = rs.getDouble(3);
System.out.print(" name " + firstname + "." + dname);
System.out.println(" , salary " + String.valueOf(salary));
}
rs.close();
stmt.close();
con.close();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("=========cricle : "+String.valueOf(k)+"=======");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -