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

Not getting the desired row displayed

 
Fungsuk Wangdu
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am learning JDBC, completely new to it. I know MySQL very well. I have a search form in my applet (tab 2), where I search for food. And when I click search, I want it to search for the exact food from the Database and return the table contents of that particular row alone. But I am not getting any result. Only an empty frame opens. But when I put the query as "SELECT * FROM table", I am getting the complete table. But I want only one row, the one that is searched for. Can anyone please tell me where I am going wrong? Here's my code:



My table has the following fields: id, name, category, origin, taste, type.

Can anyone please check out the code on your comp, try it out and help me with it?

Thanks
 
T Mishra
Ranch Hand
Posts: 108
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"SELECT * FROM delicious WHERE name = "+s+""

The problem is in the sql query syntax.
 
Fungsuk Wangdu
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried your Query too. Even that doesn't work. Can anyone please try this out in Eclipse and tell me?
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fungsuk Wangdu wrote:I tried your Query too.

What T Mishra posted is your query, singled out so as to help you spot the problem with the syntax. Do you see what is wrong with it? (Hint: what is the syntax to enter string literals in MySQL queries?)

Instead of fixing the syntax, you should actually switch to using PreparedStatements. They make your code more efficient, portable and secure. See our page on PreparedStatement.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic