星期二, 一月 16, 2007

DBCon.java

package common;
import java.sql.Connection;import java.sql.DriverManager;import java.sql.SQLException;
public class DBCon { public static Connection getConnection() { Connection con=null; String CLASSFORNAME="com.ibm.db2.jcc.DB2Driver"; //String CLASSFORNAME="com.ibm.db2.jdbc.app.DB2Driver"; String SERVANDDB="jdbc:db2://localhost:50000/test11"; String USER="db2admin"; String PWD="db2admin"; try { Class.forName(CLASSFORNAME).newInstance(); con = DriverManager.getConnection(SERVANDDB,USER,PWD); }catch(SQLException e){ System.out.println("aaaaa"); while(e != null) { System.out.print("SQL State: " +e.getSQLState()); System.out.print("Vendor Specific code: " +e.getErrorCode()); e = e.getNextException(); }
System.out.println("bbbbbb"); } catch(Exception ex) { System.out.println("EX State: " +ex.getMessage()); System.out.println("WEX code: " +ex.getStackTrace()); } return con; }}

没有评论: