• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

prepared statement -select- and?

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i want to write a select query but i get error
(the error is mentione the and section in select query)
String select = "Select *"+" from tseller where name=? and manfac=?";
pstmt = con.prepareStatement(select);
pstmt.setString(1,Name);
pstmt.setString(2,Manfac);
ResultSet rows = pstmt.executeQuery(select);
do you know what is wrong?
thnx,
Sahar.
 
Ranch Hand
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


do you know what is wrong?



Certainly not , unless you show us the error.
 
sahar sa
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sure! this is the error:

SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? and manfac=?' at line 1
SQLState: 42000
VendorError: 1064
do you have any idea whats wrong?
thnx
sahar
 
Marshal
Posts: 70327
283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Difficult to be sure, but you appear to be passing the ? directly to MySQL. Are you passing that select instruction via JDBC or at a command-line?
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



why do you need pass query to preparedstatement. try pstmt.executeQuery().
 
Bartender
Posts: 2658
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Balu Sadhasivam wrote:


why do you need pass query to preparedstatement. try pstmt.executeQuery().

That is a good catch. Looked over it.
 
Brace yourself while corporate america tries to sell us its things. Some day they will chill and use tiny ads.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic