• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to use two query in one servlet  RSS feed

 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends
Is that the right way I used two guery in my servlet since I have to get ID and pass it to second query:
Please advise since I have this error.
Error: Call arguments missing
PrepStmt =con.prepareStatement("select ID from statusdesc where text =" text);
^
1 error
Thanks,
Elahe
------------Part of code---------
con = getConnection();

//Create a Statement Object
stmt = con.createStatement();

PrepStmt =con.prepareStatement("select ID from statusdesc where text =" text);
ResultSetMetaData rsmd = rs.getMetaData();
while (rs.next()) {
C_BugList xobj=new C_BugList();
xobj.setBugNumber(rs.getInt("ID"));
v.addElement(xobj);
}
stmt.close();

//Create a Statement Object
stmt = con.createStatement();

//Execute an SQL query, get a resultSet
PrepStmt =con.prepareStatement("update bug set values (?,?,?,?,?) where bugNumber="+bugNumber);
PrepStmt.setInt(1,ID);
PrepStmt.setString(2,bdesc);
PrepStmt.setString(3,fixedDate);
PrepStmt.setInt(4,userID);
PrepStmt.setString(5,contact);
PrepStmt.executeUpdate();
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello -
I'm going to move this over to the servlet forum where it will get better attention.
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I admit I haven't looked any deeper than this, but what about "+ text" (you don't have the '+' symbol).
 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
GOOD CATCH thanks a lot. it killed me all morning...
The last question base on my code is, how the second query can get the value of ID from the first query(I'm not sure my code is correct..)?
------------
PrepStmt =con.prepareStatement("select ID from statusdesc where text =" +text);
ResultSetMetaData rsmd = rs.getMetaData();
while (rs.next()) {
C_BugList xobj=new C_BugList();
xobj.setBugNumber(rs.getInt("ID"));
}
stmt.close();
stmt = con.createStatement();

//Execute an SQL query, get a resultSet
PrepStmt =con.prepareStatement("update bug set values (?,?,?,?,?) where bugNumber="+bugNumber);
PrepStmt.setInt(1,ID);
...

Thanks Mike,
Elahe
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Uhhh use "getBugNumber" from your bug list object?
Kyle
 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't get your it. could you please describe more..
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What Kyle means is that you are apparently stuffing the value of the bug ID into an object of class 'C_BugList' held by the reference 'xobj' and using the method 'setBugNumber'

We propose (Kyle and me) that you retrieve the ID with the method 'getBugNumber'. If you don't have this method, then umm... well... gosh, why not?

The other condition you will quickly run across.. is that you are creating your buglist object within a block (the while block)... this object has two problems. It is not visible outside of that block, and even if it was... you'd have only the LAST record from the first resultset, to use in the second update statement.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!