• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can we use two quries using prepared statement in one method

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 33
Android Mac PPC Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,
 
Why should I lose weight? They make bigger overalls. And they sure don't make overalls for tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic