DB2 连接数据库
package com.mypkg.struts.dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class conn {
private static Connection con;
public static Connection getCon() {
try {
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver").newInstance();
con = DriverManager
.getConnection(
"jdbc:db2:pms168","pms", "pms");
} catch (Exception e) {
e.printStackTrace();
}
return con;
}
public static void main(String args[]){
try{
Connection con=conn.getCon();
Statement state=con.createStatement();
ResultSet rs=state.executeQuery("SELECT *FROM PAMS.ORGAN ORDER BY INSTNO");
while(rs.next()){
System.out.println(rs.getString(1)+" "+rs.getString(2)+" "+rs.getString(3));
}
rs.close();
state.close();
con.close();
}catch(Exception ex){
ex.printStackTrace();
}
}
}