Using the Oracle database parser from Java using JDBC

前端 未结 2 1813
误落风尘
误落风尘 2020-12-21 05:42

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.

Befo

相关标签:
2条回答
  • 2020-12-21 06:33

    I have no idea what exactly do you want to achiveve but maybe yo migh try to use package DBMS_SQL and it's method PARSE. This works only with DML statements only. This is what Oracle SQL Developer does.

    This parser might be used for DML statements too. For PL/SQL it will need some tweaking. As far as I know nobody spent enough time to create a real fully validating parser for Oracle's DDL.

    Here is an example how I use it:

    declare 
     l_cursor number := dbms_sql.open_cursor; 
     l_offset number := -1 ; 
    begin 
      begin 
        dbms_sql.parse( l_cursor, :st, dbms_sql.native ); 
      exception when others then
       l_offset := dbms_sql.last_error_position;
      end;
    dbms_sql.close_cursor( l_cursor );
      :off := l_offset;
    end;
    

    Simply execute this block. Pass one input parameter of type VARCHAR2(String) (max 32KB) and one output parameter NUMBER.

    0 讨论(0)
  • 2020-12-21 06:43

    Without executing the Query, your cannot get a feedback(or resultset, about it. Connection.preparedStatement just return you a PreparedStatement object, which is just a handler.

    PreparedStatement.executeQuery() is only what executes the query actually, pushing to the database.

    0 讨论(0)
提交回复
热议问题