File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes How to validate the syntax of a SQL query without executing it using JDBC? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "How to validate the syntax of a SQL query without executing it using JDBC? " Watch "How to validate the syntax of a SQL query without executing it using JDBC? " New topic
Author

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

ranjani ra
Greenhorn

Joined: Feb 13, 2013
Posts: 3

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

Joined: Mar 01, 2009
Posts: 1703
    
  14

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.


No more Blub for me, thank you, Vicar.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to validate the syntax of a SQL query without executing it using JDBC?