数据库连接的怪异问题,求教。

大家好,写了个测试程序 在连接数据库时执行到con = DriverManager.getConnection(URL, "testdb2", "123456");这句话时就没反应了不知道为什么?也没有异常出现,也不向下执行? 求各位指点一下, 谢谢 :cry:

执行结果如下:
[color=green]驱动接口程序连接成功!!!
1111[/color]

[code="java"]public class ImportDB2 {

private static String driver = "COM.ibm.db2.jdbc.net.DB2Driver";

private static String URL = "jdbc:db2://192.168.1.102:50001/testdb2";

private static String username = "admin";

private static String password = "123456";

private static Connection con = null;

private static PreparedStatement pstmt = null;

private static ResultSet rs = null;

public static void main(String [] args) {
    createXML();
}

public static void createXML() {
    try {
        Class.forName(driver);
        System.out.println("驱动接口程序连接成功!!!");
        System.out.println("1111");
        con = DriverManager.getConnection(URL, "testdb2", "123456");
        System.out.println("2222");
        if (!con.isClosed()) {
            System.out.println("连接DB成功!!!");
    }
    } catch (Exception e) {
        e.printStackTrace();
    }

    try {

    } catch (Exception ex) {
        System.out.println("连接DB失败!!!" + driver);
        ex.printStackTrace();
    }
    System.out.println("333");
    StringBuffer sb = new StringBuffer("<?xml version=\"1.0\" encoding=\"utf-8\"?><ImportDataList>");

    File file = new File("F:\\My Document\\DB2Data\\20100617\\test");
    String [] fileNames = file.list();

    for(int i=0; i<fileNames.length; i++) {

// System.out.println(fileNames[i]);
sb.append(" sb.append("Trl=\"db2://sino_zsk@SINO/TABLE/SINO_ZSK/" + fileNames[i].substring(0,fileNames[i].indexOf(".")) + "\" ");
sb.append("ColumnNames=\"True\" BlankAsNull=\"True\" ");
sb.append("Encoding=\"Chinese Simplified (GB2312)\" FirstDataRow=\"2\" ");
sb.append("Truncate=\"False\" NewTableName=\"\" NewTableColType=\"\" ");
sb.append("NewTableColSize=\"0\" Identity=\"False\" SpanInputSource=\"False\" ");
sb.append("BlockInsertValue=\"1024\" Quote=\""\" Delimiter=\",\">");
sb.append("");

        int num = 9;
        for(int j=num; j>=0; j--) {
            sb.append("<MappingItem Key=\""+j+"\" Value=\""+j+"\" />");
        }
        sb.append("</MappingList></ImportData>");
    }

    sb.append("</ImportDataList>");

    System.out.println(sb.toString());
}

}[/code]

2个回答

你试着换个端口试下.6789,50000
没往下执行,估计是你的驱动,没注册起来

con = DriverManager.getConnection(URL, "testdb2", "123456");
这里的"testdb2"应该是用户名"admin"吧,你的url里面已经包含有数据库名了

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问