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

Programatically validate SQL Syntax

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any ideas on how to programatically validate the syntax of a SQL statement for Oracle without executing and WITHOUT connecting to the database?
I'm open to ideas.
Thanks in advance for any help!
Eric
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not what you asked for, but: you can create a PreparedStatement without executing anything. That should test validity. You still need to connect to a database though.
You could also avoid connection to your "real' database by using an alternate db. Perhaps something like mckoi, which can beeasily packed in a jar file and distributed with the rest of your application. If your target DB is something more powereful, like Oracle for example, you may find that mckoi knows nothing about the high-level features you wish to use. But for parsing simple stuff it may work great.
Otherwise, I think you may find yourself writing your own custom parser. I believe there are varios tools out there that can help you with this (a Java version of lexx for example) but I'm not too familiar with these currently.
 
Eric Rockenbach
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Will the PrepatedStatement also validate that the table and columns actually exist? I DON'T want to verify if the tables and columns exist, but instead only the syntax minus the existance of objects. I like your approach, but I want to make sure that I wouldn't have to recreate a database structure inside the thin db that you recommended.
Thanks again for all the help!
Eric
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
EasySQL Checker is a shareware product that can validate the SQL. This may help if you don't actually need the code.
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Validating from Databse without connecting Database is Not Possible _ so _ whats _ new _ ??
In our project, all the clases that fire/prepare SQL statements are implement a interface, this Interface have all the table names .

so this gives a advantag as to we can any day find out what this wiered table/field name stands for, and chances of coding error are less...
_what say _ ???
Cheers
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Eric,
Though I have never used it myself, I believe, Oracle's SQLJ checks syntax of SQL statements embedded in Java programs... you might want to have a look at it!
I hope this Oracle link works...
HTH,
Abhik.
 
If you have a bad day in October, have a slice of banana cream pie. And this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic