Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

prepared statement -select- and?

 
sahar sa
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.
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • 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
 
Campbell Ritchie
Sheriff
Posts: 51453
87
  • 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 Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



why do you need pass query to preparedstatement. try pstmt.executeQuery().
 
Jan Cumps
Bartender
Posts: 2608
14
C++ Linux Netbeans IDE
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic