• 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
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Verifying an sql statement is syntactically correct

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I am trying to find a java api that can verify whether a sql statement has been written syntactically correct. My sql statements will be dynamically created at run time, and I would like to have them verified proir to sending to the db, rather than wasting time running the search and then finding the statement contained flaws.
My db is Oracle9iRelease2.
Regards
Bill
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thats kind of tough because it is dynamically created. Testing you code is one way to make sure that the query built will always be correct. Catching the Exceptions will also work, or have you tried using the dynamic query package in Oracle, dbms_sql.
Question at AskTom that might help:
First.
or do a search at AskTom, there are lots of them in his archives.
Mark
 
Ranch Hand
Posts: 925
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i don't see what is wrong with catching the syntax errors?
I'd say writing an sql syntax checker is a bigger waste of time.
 
William Wild
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Simon,
What I am doing is to create an sql statement from an xpath statement. So I need the verification (principly during the construction of the parser) so I can check the resultant.
Mark
Having a look at it all now. Thanks for the pointer to AskTom, didn't even know that was there :-)
Cheers
Simon
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi William,
The way we do that is to prefix the SQL statement with "EXPLAIN PLAN FOR ", and then invoke the "executeUpdate()" method (of class "[Callable/Prepared]Statement". This merely parses the SQL statement (and throws an "SQLException" if it is incorrect).
Does this help you?
Good Luck,
Avi.
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Avi, that is a great idea. that way you not only have the SQL parsed if it is correct, but you can also get the syntax part down.
Mark
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic