• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Prepared Statement execution not returning any data

 
dennis zined
Ranch Hand
Posts: 330
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a prepared statement with a simple query...my problem is that it does not return any data. For example,



If I use the same sql but with inline parameters...it returns me the data I expect. For example,



There was a similar post at experts-exchange but I have to pay to see the solution.

Has anybody encountered this before?

Thanks.
 
Julian Kennedy
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dennis,

I've not encountered this problem, but can you give a real example and state which database and JDBC driver you're using?

Jules
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34965
378
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dennis,
You actually don't have to sign up to see the solution. Just keep scrolling down past all the ads and you see the answers.
 
Julian Kennedy
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, so to summarise:
  • Ensure that you're not getting any exceptions, e.g. ones that you're ignoring with code like catch(Exception e) { }
  • Ensure that your SQL returns rows when executed in the database directly, i.e. outside Java
  • Ensure that you're connecting using the same credentials (i.e. machine, database, user/schema, etc.)
  • Ensure that the data you're trying to read has been committed if it was added in a different session. Alternatively set the transaction isolation in Java for dirty reads using code like con.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED); WARNING: do this only if you mean it and know what you're doing

  • Hope that helps.

    Jules
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic