0
//Class UserProfileDBUtil.java

Connection conn = null;
PreparedStatement statment = null;
    ResultSet rs = null;
    try{
        String sqlString = "select count(*) from "+AGENCY_SCHEMA_NAME+".AGENCY         WHERE AGENCYCODE= ? and ENABLEDFLAG = ?";
        conn = JDBCUtils.getConnection(JDBCUtils.WP_ODS);
        statment = conn.prepareStatement(sqlString);
        statment.setString(1, agencyCode.toUpperCase());
        statment.setString(2, "Y");
        rs =statment.executeQuery();  // SQL Error Line 42
        while(rs.next())
        {
            if(rs.getInt(1) > 0 )
            {
                return true;
            }
        }
        log.error("Agency for agency code "+agencyCode+" is not available or not active");
    }

LOG :

com.ibm.db2.jcc.b.SqlException: DB2 SQL error: SQLCODE: -401, SQLSTATE: 42818, SQLERRMC: = at com.ibm.db2.jcc.b.sf.e(sf.java:1680) at com.ibm.db2.jcc.b.sf.a(sf.java:1239) at com.ibm.db2.jcc.c.jb.h(jb.java:139) at com.ibm.db2.jcc.c.jb.a(jb.java:43) at com.ibm.db2.jcc.c.w.a(w.java:30) at com.ibm.db2.jcc.c.cc.g(cc.java:161) at com.ibm.db2.jcc.b.sf.n(sf.java:1219) at com.ibm.db2.jcc.b.tf.gb(tf.java:1818) at com.ibm.db2.jcc.b.tf.d(tf.java:2294) at com.ibm.db2.jcc.b.tf.X(tf.java:508) at com.ibm.db2.jcc.b.tf.executeQuery(tf.java:491) at com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.executeQuery(WSJdbcPreparedStatement.java:559) at UserProfileDBUtil.isAgencyActive(UserProfileDBUtil.java:42)

  • Please Note : Exception is throwing only on my system. Using webspere app server 6.1. Connection and statement are both not null. Code working perfectly on other systems. JDK : websphere jdk 6.1 – akhilesh gupta Jan 10 '13 at 12:29
  • On different systems, you could well be using different versions of the DB2 JDBC driver, which sometimes means different ways of mapping between Java types and SQL column types. Check your JDBC driver version levels, and also post the SQL column types here. – dbreaux Jan 10 '13 at 18:09

1 Answers1

1

The error you're getting is a -401, which means:

The data types of the operands for the operation operator are not compatible or comparable.

I would check and make sure that the parameters you're passing in are using the right data types. If you catch the exception, you should be able to use the exceptions Message property to see what the operator is. See here for an example.

bhamby
  • 15,112
  • 1
  • 45
  • 66
  • Hi..I just found if i try preparedstmt.setString(1,locale) then error comes. If i set the locale in query as "where locale = "+locale+" , it works fine. So issue in in setString method and in any query with same datatype – akhilesh gupta Jan 11 '13 at 09:53