• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can we use two quries using prepared statement in one method

 
Adnan Gondal
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI all!

Can we use two quries in one method while using prepared statement, i have tried using this but invalid column name exception is comeing. Any idea please?

My code snippets is as follows.

 
Paul Clapham
Sheriff
Pie
Posts: 20719
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, yes, you can. You're getting the "invalid column name" error because one of the two queries has an invalid column name. (Sometimes it's better to treat the error messages as if they are providing you useful information about what you did wrong...)

In your case I'm guessing that "employeeID" isn't the name of a column in the "attendance" table. If that's the case then you should use the PreparedStatement feature where you can use "?" as a place-holder and then set its value via the setInt or setString method or another one like it.

You might also consider using a "select count(*) ..." query which returns a single record containing the number you want, instead of writing Java code to drag all of the records across the network and then do nothing except count them.

By the way this applies to Java in general, because Java code written for a JSF application is still Java code.
 
Ankit Thakkar
Ranch Hand
Posts: 33
Android Java Mac PPC
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kajal,

By looking at you code, looks like from employee table you fetch employee data and seach attendance records in attendance table. I would recommend to create join query to get data from employee, attendance tables in single db call. Also you should use "?" when you have PreparedStatement.

for your query, try after changing query as below
"select att_status from attendance where e_id="+employeeId;

Thanks,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic