aspose file tools*
The moose likes JDBC and the fly likes PreparedStatement return empty resultset, but statement returns row values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "PreparedStatement return empty resultset, but statement returns row values" Watch "PreparedStatement return empty resultset, but statement returns row values" New topic
Author

PreparedStatement return empty resultset, but statement returns row values

divya kundapur
Ranch Hand

Joined: Aug 21, 2007
Posts: 110
"select b.* from test1 a, test2 b where aid=? and b.id=? "+
"and a.cd=? and a.a_id=? and a.nb=? and a.ab_id=? and a.am=?";

same select when i pass it to statement object i m getting a result set but preparedstatement return empty result set


SCJP - 5.0
amit punekar
Ranch Hand

Joined: May 14, 2004
Posts: 516
Hello,
If you can let us know how you are using Statement and PreparedStatement in your code then it might help.

regds,
amit
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1479
    
    6

Are you sure that you are setting the values in PreparedStatement properly?


Swastik
divya kundapur
Ranch Hand

Joined: Aug 21, 2007
Posts: 110


amit punekar
Ranch Hand

Joined: May 14, 2004
Posts: 516
Hi,
What are the datatypes in the DB for the columns ?
After carefully looking at the code below I think the temp.get(2) is being passed as String in the PreparedStatement and as an Object in the Statement.
You may want to check this.

Also please give it a thought why you are using setObjects in couple of places and setString at some. Depending upon your datatypes you can use most appropriate setXXX which would help reduce the confusion.

regds,
Amit
divya kundapur
Ranch Hand

Joined: Aug 21, 2007
Posts: 110
amit punekar wrote:Hi,
What are the datatypes in the DB for the columns ?
After carefully looking at the code below I think the temp.get(2) is being passed as String in the PreparedStatement and as an Object in the Statement.
You may want to check this.

Also please give it a thought why you are using setObjects in couple of places and setString at some. Depending upon your datatypes you can use most appropriate setXXX which would help reduce the confusion.

regds,
Amit


left side is the table datatypes and right side i have the way i m setting the parameters for my preparedstatement

VARCHAR2(40 BYTE) -- pstmt.setString(1,"'"+temp.get(0)+",')
CHAR(2 BYTE) -- pstmt.setString(1,"'"+temp.get(1)+",')
CHAR(4 BYTE) -- pstmt.setObject(2,temp.get(2))
VARCHAR2(40 BYTE) -- pstmt.setObject(2,temp.get(3))
VARCHAR2(40 BYTE) -- pstmt.setObject(2,temp.get(4))
NUMBER(19,0) -- pstmt.setObject(2,temp.get(5))

any help
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19783
    
  20

Moving to our JDBC forum.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
divya kundapur
Ranch Hand

Joined: Aug 21, 2007
Posts: 110
divya kundapur
Ranch Hand

Joined: Aug 21, 2007
Posts: 110
can somebody help me,, i have hardcoded values into the parameters and its working fine, but not when i pass it from an arraylist.
amit punekar
Ranch Hand

Joined: May 14, 2004
Posts: 516
Hi,

VARCHAR2(40 BYTE) -- pstmt.setString(1,"'"+temp.get(0)+",')
CHAR(2 BYTE) -- pstmt.setString(1,"'"+temp.get(1)+",')

This looks a bit confusing ",' ??


regds,
Amit
nnk navi
Greenhorn

Joined: Feb 04, 2011
Posts: 4
Hope your return tyoes of your getMethods are appropriate? Can you please check that?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: PreparedStatement return empty resultset, but statement returns row values