简体   繁体   中英

How to use fixed length CCSID 37 char value in where clause of sql select for IBM DB2 iSeries in node.js

My application is connected to IBM DB2 iSeries database connected through DataDirect approach using db2.jar in Java. When I run any select query with specific data in where clause it do not detect the value that I pass in where condition. Data type for that column is of CHAR(7) and I am passing a value as 'P544901'. How can I use this or any other 7 char value and db can detect it. Is there any other process that can solve my problem.

Sample Code in Java -

String sql = "SELECT poMast.ORDNO  from AMFLIBL.POMAST AS poMast WHERE poMast.ORDNO =  ? ";
Class.forName("com.ddtek.jdbc.db2.DB2Driver");
String url = "jdbc:datadirect:db2://hostname:port;DatabaseName=dbName;";
Connection con = DriverManager.getConnection(url, "username","password");
PreparedStatement preparedStatement = con.prepareStatement(sql);
preparedStatement.setString(1, 'P544901');
ResultSet rs = preparedStatement.executeQuery();
System.out.println("ResultSet : \n");
System.out.println(" VNDNO");
while (rs.next())
{
   System.out.println(rs.getString("ORDNO"));
}

尝试像这样修改(用双引号替换简单引用)

preparedStatement.setString(1, "P544901");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM