Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing the Oracle database parser from Java using JDBC
    primarykey
    data
    text
    <p>I'm writing a tool in Java which submits statements to a database, which are later run. I'm using JDBC to connect to the database. The database is Oracle 10g.</p> <p>Before the statements are written to the database I want to parse them to check when they run later there will be no problems. I looked into using an ANTLR solution to this as there are grammars available, but surely If I have a connection to the database there must be a way to use the databases built in parser.</p> <p>So essentially my question is:</p> <p>Is there a way using JDBC I can make a call to the database parser passing it an SQL statement and it will return me some sort of feedback, telling me if it was successful or any error messages?</p> <p>Any help is greatly appreciated, Many thanks.</p> <p>Edit:</p> <p>Using connection.prepareStatement does not seem to work for instance this outputs parsed successfully! </p> <pre><code>String statement = "WHERE DISTINCT SELECT"; Connection connection; try { connection = this.controller.getDataSource().getConnection(); connection.prepareStatement(statement); connection.close(); mainPanel.setPositiveText("Parsed Successfully!"); } catch (Exception e) { mainPanel.setNegativeText("ERROR: " + e.getMessage()); return; } </code></pre> <p>The soultion I used is as follows:</p> <pre><code> String statement = "DECLARE " + "myNumber NUMBER; " + "BEGIN " + "myNumber := SYS.dbms_sql.open_cursor; " + "SYS.DBMS_SQL.PARSE(myNumber, '" + text + "', SYS.DBMS_SQL.NATIVE); " + "END;"; Connection connection; try { connection = this.controller.getDataSource().getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(statement); preparedStatement.execute(); connection.close(); mainPanel.setPositiveText("Parsed Successfully!"); } catch (Exception e) { mainPanel.setNegativeText("ERROR: " + e.getMessage()); System.out.println(e.getMessage()); return; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload