Search code examples
javaprepared-statementresultset

Java prepared statement does not allow large strings in the where clause of the query


I am trying to retrieve data from DB2 using Java prepared statement

String select_statement = "SELECT * FROM schema_name.table_name where NME='xxx002' and LINE =7200 and FILE_NME='720001042021XYZ002' with ur";

try (Connection connection = DataBaseConnection.getGeoCarDBConnection_TESTDATA(); 
                PreparedStatement ps = connection.prepareStatement(select_statement);)  {
        ResultSet rs = null;
        rs = ps.executeQuery();
}

The problem I am facing is that I include the FILE_NME in the where clause of the query, as shown above, 0 rows are returned. But any other string fields can be passed and I get the desired number of rows.

Any integer fields in the where clause works too. But only the string fields that are large(In this case, FILE_NME field) are not working. In the DB2 table, where I am pulling the data from, the FILE_NME field is of varchar(30).

Things that did not work for me was

String select_statement = "SELECT * FROM schema_name.table_name where NME='xxx002' and LINE =7200 and FILE_NME = ? with ur";

then I set the String value using,

ps.setString(1, "'720001042021XYZ002'")

ps.setString(1, "720001042021XYZ002")

Both did not work.

None of the google links were helpful. Have spent more than a day on it.

This code used to work flawlessly before, Even the java version hasn't changed(as per my knowledge)

I am running it in windows 10.

Java version : 1.8 ((build 1.8.0_221-b11))

I run the same query in the database client and it works.

Someone please help me or point me in the right direction. I don't know what I am missing

Thank in advance


Solution

  • The problem was that there was indeed no data, I was checking the same query in the database client in a different environment. I am closing this.