aspose file tools*
The moose likes JSF and the fly likes Can we use two quries using prepared statement in one method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Can we use two quries using prepared statement in one method" Watch "Can we use two quries using prepared statement in one method" New topic
Author

Can we use two quries using prepared statement in one method

Adnan Gondal
Ranch Hand

Joined: Apr 30, 2011
Posts: 35
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
Bartender

Joined: Oct 14, 2005
Posts: 18989
    
    8

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

Joined: Apr 29, 2005
Posts: 33

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,

- Ankit
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can we use two quries using prepared statement in one method