简体   繁体   中英

sql query returning 0 rows

I have this sql query which runs fine and return 3 rows when run on sql developer but when I execute the same query in a jsp page, it executes properly but doesn't return any rows. There is no problem with database connection because all other queries work fine.
Server - Tomcat 7
database - Oracle 10g

query -

select slno from lbk_tab where log_date = to_date('18-06-2017','DD-MM-YYYY')

jsp -

String dtol = "select slno from lbk_tab where log_date = to_date('18-06-2017','DD-MM-YYYY')";
Statement st = connection.createStatement();
ResultSet resultSet = st.executeQuery(dtol);
if (resultSet.next()) {
     out.print(Integer.parseInt(resultSet.getString(1)));
}

Table lbk_tab has columns slno and log_date.

How can I fix this?

Try these things :

  1. Classfiles are being generated afresh ? Clear & re-build project / workspace.
  2. Print the query and try to run printed query. Theoretically it looks the same from code, but just to be sure..
  3. Check for query being fired at database also, may be java messes with date object or date format. Hence the actual date fired from jsp says something else while fired at mysql points at something else ? debug / log / print query actually fired at mysql end.
  4. More clarity is required here, "to_date" referenced in query is function ? what are column types.

我认为你需要使用to_char()

select slno from lbk_tab where log_date = to_char(to_date('18-06-2017','DD-MM-YYYY'))

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