今天开发伙伴的一个问题,学了一招,记下做备忘:
import java.sql.*;
public class connnectDB2{
/** *//**
* @param args
*/
public static void main(String[] args){
// String driver = "com.ibm.db2.jcc.DB2Driver";
// driver = "com.ibm.as400.access.AS400JDBCConnection";
// String url = "jdbc:db2://10.10.1.33:23/MMIF8DVL";
String userName = "UFIDA";
String passWord = "UFIDAMTH";
Connection conn = null;
Statement st = null;
ResultSet rs = null;
String sql = null;
try{
// Class.forName(driver).newInstance();
// conn = DriverManager.getConnection(url, userName, passWord);
// conn = DriverManager.getConnection("jdbc:as400://10.10.1.33:23/MMIF8DVL,userName,passWord");
java.sql.DriverManager.registerDriver (new com.ibm.as400.access.AS400JDBCDriver ());
Class.forName("com.ibm.as400.access.AS400JDBCConnection");
conn = DriverManager.getConnection("jdbc:as400://10.10.1.33",userName,passWord);
st = conn.createStatement();
st.execute("set current schema mmif8dvl");
sql = new String("SELECT ASNUM FROM MMIF8DVL.if8vdr");
rs = st.executeQuery(sql);
while(rs.next()){
System.out.println(rs.getString(1));
}
conn.close();
} catch (Exception e){
System.out.println("error:" + e.getMessage() );
System.out.println(e.toString());
}
}
}