DB2 AS / 400通过JDBC查询?

时间:2015-04-08 06:06:29

标签: java jdbc encoding db2 ibm-midrange

我正在尝试处理需要查看现有DB2 AS / 400服务器数据的Java项目,但一直告诉我这个错误:

com.ibm.db2.jcc.am.to: [jcc][t4][10379][11959][4.8.87] Client disconnect exception encountered: [jcc][10275][10261]Unsupported ccsid, encoding, or locale: "65535". ERRORCODE=-4499, SQLSTATE=null
    at com.ibm.db2.jcc.am.gd.a(gd.java:321)
    at com.ibm.db2.jcc.am.gd.a(gd.java:347)
    at com.ibm.db2.jcc.t4.fc.e(fc.java:2245)
    at com.ibm.db2.jcc.t4.fc.e(fc.java:2134)
    at com.ibm.db2.jcc.t4.db.c(db.java:4439)
    at com.ibm.db2.jcc.t4.db.b(db.java:4384)
    at com.ibm.db2.jcc.t4.db.a(db.java:4370)
    at com.ibm.db2.jcc.t4.eb.oc(eb.java:349)
    at com.ibm.db2.jcc.t4.fb.o(fb.java:830)
    at com.ibm.db2.jcc.t4.fb.g(fb.java:143)
    at com.ibm.db2.jcc.t4.fb.a(fb.java:40)
    at com.ibm.db2.jcc.t4.t.a(t.java:32)
    at com.ibm.db2.jcc.t4.ub.i(ub.java:135)
    at com.ibm.db2.jcc.am.wm.hb(wm.java:1949)
    at com.ibm.db2.jcc.am.wm.a(wm.java:2968)
    at com.ibm.db2.jcc.am.wm.a(wm.java:659)
    at com.ibm.db2.jcc.am.wm.executeQuery(wm.java:643)
    at Main.main(Main.java:78)
Caused by: java.io.UnsupportedEncodingException: [jcc][10275][10261]Unsupported ccsid, encoding, or locale: "65535".
    at com.ibm.db2.jcc.am.bb.a(bb.java:1125)
    at com.ibm.db2.jcc.t4.fc.e(fc.java:2242)
    ... 15 more

这些是我的图书馆:

 db2jcc4.jar
 db2jcc_license_cisuz.jar

我的代码:


    public class Main
    {
        public static void main(String[] args) throws UnsupportedEncodingException
        {
            try
            {

                Class.forName("com.ibm.db2.jcc.DB2Driver");

            }
            catch (ClassNotFoundException e)
            {
                e.printStackTrace();
                return;
            }

            //DB2DataSource
            System.out.println("DB2 driver is loaded successfully");
            Connection conn = null;
            PreparedStatement pstmt = null;
            Statement statement = null;
            ResultSet rset = null;
            boolean found = false;

            try
            {
                Properties properties = new Properties();
                properties.put("user", "USER");         // Set user ID for connection
                properties.put("password", "password");     // Set password for connection
                String url = "jdbc:db2://myserver:446/mydb";

                conn = DriverManager.getConnection(url, properties);


                if (conn != null)
                {
                    System.out.println("DB2 Database Connected");
                }
                else
                {
                    System.out.println("Db2 connection Failed ");
                }


                String sql = "SELECT * FROM ZIPFILES.POLHDR;";
                statement = conn.createStatement();
                rset = statement.executeQuery(sql);


            }
            catch (SQLException e)
            {
                System.out.println("DB2 Database connection Failed");
                e.printStackTrace();
                return;
            }
        }
    }

其他信息:

  1. 错误指向此行

    rset = statement.executeQuery(sql);
    
  2. DB2 AS / 400版本是V4R4

  3. 表的编码是CCSID 37,但我尝试将所有内容更改为该编码(例如CP037,IBM037),但没有运气!我也试过循环每个可能的编码(哈哈),但仍然没有运气!

1 个答案:

答案 0 :(得分:2)

根据错误消息,文件编码似乎是65535(即二进制数据),而不是37.

尝试将以下属性附加到连接字符串:translate binary=true;ccsid=37;