• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

PreparedStatement return empty resultset, but statement returns row values

 
divya kundapur
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
 
amit punekar
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1625
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure that you are setting the values in PreparedStatement properly?
 
divya kundapur
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


 
amit punekar
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20610
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to our JDBC forum.
 
divya kundapur
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
divya kundapur
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 544
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hope your return tyoes of your getMethods are appropriate? Can you please check that?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic