File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to validate the syntax of a SQL query without executing it using JDBC?

 
ranjani ra
Greenhorn
Posts: 3
Hibernate Java Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to validate the syntax of a SQL query without executing it using JDBC?

I know about the 'set noeexec on' in Sybase, but I want to use a similar functionality in JDBC call.

The command 'set noexec on' in Sybase works if used in a env like Rapid SQL. However I want to use it with Prepared statements.

[code=java]String sqlValue = "select * from table_name";
Connection conn = ConnectionPool.getConnection();
PreparedStatement pstmt = conn.prepareStatement(sqlValue);
boolean queryValidityResult = pstmt.execute();[/code]
Is it right to use the 'set noexec on' like this?

[code=java]String sqlValue = "set noexec on " + "select * from table_name";
Connection conn = ConnectionPool.getConnection();
PreparedStatement pstmt = conn.prepareStatement(sqlValue);
boolean queryValidityResult = pstmt.execute();[/code]
Or is there any setter property on PreparedStatement which would help?

Or is there any other way by which I can just validate my SQL instead of executing it?

Any ideas?
 
chris webster
Bartender
Pie
Posts: 2369
31
Linux Oracle Postgres Database Python Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should write and test your SQL in your database's SQL interpreter before putting it into your Java code. This is the quickest and most reliable way to ensure that your SQL is valid, that it runs against the tables/columns in your database schema, and that it returns the correct results. Until you have done this, your SQL is just a string that might or might not be correct. Once you know your SQL is correct, you can put it into your Java code. Don't be afraid of the database: if you are writing SQL you should know how to execute it in your database. If you are afraid of executing SQL in your database, you shouldn't be writing SQL in the first place.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic