• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Correct syntax of SQL query in PreparedStatement

 
Shubham Semwal
Ranch Hand
Posts: 176
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm getting weird errors while trying to use prepareStatement().

1:


Output - f_name
expected - "Some_name from database"

it's working fine if I use -


Also I'm not able to use ? in place of table name.
Please suggest.
 
Paul Clapham
Sheriff
Posts: 21551
33
Eclipse IDE Firefox Browser MySQL Database
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that's right, you can't use table names or column names as place-holders in PreparedStatements. But fortunately you don't need to do that in the example you posted.
 
Shubham Semwal
Ranch Hand
Posts: 176
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay.. Thanks
 
Brian Tkatch
Bartender
Posts: 567
25
Linux Notepad Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just reiterating what has already been said: Placeholders can be used in place of data, not objects, or any other part of the statement.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shubham Semwal wrote:Also I'm not able to use ? in place of table name.

In your code snippet you are not using the placeholder ? in place of the table name, but in place of a column name Luckily it doesn't matter: as already mentioned by several other ranchers, you can only use placeholders in place of values (data), not for any other part of a SQL statement.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic