日期:2014-05-20 浏览次数:20843 次
import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class ConDB { private static Connection getConnection() { Connection conn = null; try { String url = "jdbc:db2://192.168.1.254:50000/TEST"; String driver = "com.ibm.db2.jcc.DB2Driver"; String uid = "db2admin"; String pwd = "123456"; Class.forName(driver); conn = DriverManager.getConnection(url, uid, pwd); return conn; } catch (ClassNotFoundException e) { System.out.println("driver wrong Problem~"); e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } return null; } public static void main(String[] args) { try { // create data source Connection conn = null; conn = getConnection(); System.out.println("连接成功"); } catch (Exception e) { e.printStackTrace(); } } }