aspose file tools*
The moose likes JDBC and the fly likes Java Prepared Statement  execution not returning any data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Java Prepared Statement  execution not returning any data" Watch "Java Prepared Statement  execution not returning any data" New topic
Author

Java Prepared Statement execution not returning any data

dennis zined
Ranch Hand

Joined: Mar 07, 2003
Posts: 330
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.


SCJP 1.4<br />SCWCD 1.4
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
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

Joined: May 26, 2003
Posts: 30929
    
158

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
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
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Java Prepared Statement execution not returning any data