• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Prepared Statement vs. select

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello folks,

I am trying to use a prepared statement to select a particular row or a set of rows (does not matter ! ). I could use prepared statement to update rows but not to retrieve them from a MySQL Database.
I used parametric statements in other languages like php and asp, it must be a solution with JDBC, to get a result from a parametric query.




The code runs without errors but also without results !

waiting for your comments

Thanks !
 
Sheriff
Posts: 28320
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, that looks like invalid SQL to me. I don't know what it's supposed to return, I can't even figure out what the column names in the resulting table would be.

But besides that, you do need to set the parameters for the PreparedStatement before you execute the query.
 
Faiz Abdelhafid
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello

My query is something like



parameter is an integer value like 2093, 2039, etc.

to clarify more my request:
If I would re-write it in another language it would be like the following:



what do you suggest ?

Thank you
 
Paul Clapham
Sheriff
Posts: 28320
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
I suggest you set the parameters for the PreparedStatement before you execute the query. In fact I believe I already suggested that.
 
Faiz Abdelhafid
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Yes in fact you mentioned that before, but you also wrote that my sql query is invalid.

besides the parameters where is the problem ?

Thanks
 
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Faiz Abdelhafid wrote:
Yes in fact you mentioned that before, but you also wrote that my sql query is invalid.
besides the parameters where is the problem ?


Hi,

here is your code:

so your query is like this:


I am not an SQL expert, but as I know, comparison (logical) operator '=' is allowed in expressions after a WHERE/HAVING keywords,
but is not allowed after a SELECT keyword.
I tried to run this query on Oracle and got an error: "FROM keyword not found where expected"
 
Faiz Abdelhafid
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I already found the correct syntax. First, I thought that Java parametric Queries are just like any other language, but it's a little bit different from PHP and ASP.



Best Regards,
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
May be you code is wrong..
I think it's like this:

remember try catch the exception and throw out so that you can know where the wrong..
 
Do you want ants? Because that's how you get ants. And a tiny ads:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic