Can I use JDev eSDK to parse Oracle SQL?

Advertisement
Is it possible to use oracle.javatools.db and oracle.javatools.db.sql to parse a sql?
import oracle.javatools.db.*;
import oracle.javatools.db.sql.*;
import java.sql.Connection;
import java.sql.DriverManager;
public class TestParser
public static void main(String[] args)
Connection conn = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:sample", "sample", "sample");
Database db = DatabaseFactory.findOrCreateDatabase("sample", conn);
Schema schema = db.getDefaultSchema();
SQLQuery sql = SQLQueryBuilderFactory.createQuery(db, schema, args[0]);
catch (Exception e) {
e.printStackTrace();
} finally {
try {
     if (conn != null)
     conn.close();
catch (Exception se) {
Now if run it with a select * from foo, the program will pass, but as soon as I list column names in the select list, like "select bar from foo", the program will fail with the following stack trace:
Exception in thread "main" java.lang.StackOverflowError
at java.lang.StringBuffer.<init>(StringBuffer.java:80)
at oracle.jdbc.dbaccess.DBError.getMsgKey(DBError.java:1358)
at oracle.jdbc.dbaccess.DBError.findMessage(DBError.java:786)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:176)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:269)
at oracle.jdbc.driver.OracleConnection.getMetaData(OracleConnection.java:1593)
at oracle.javatools.db.AbstractDatabase.getConnection(AbstractDatabase.java:171)
at oracle.javatools.db.DatabaseFactory.createConnection(DatabaseFactory.java:149)
at oracle.javatools.db.AbstractDatabase.reconnect(AbstractDatabase.java:197)
at oracle.javatools.db.AbstractDatabase.getConnection(AbstractDatabase.java:175)
... Repeat the last three lines
Can someone help me with this issue?
Thanks,
Advertisement

Replay

I think I understand the issue as any call to oracle.javatools.db.Database would close the java.sql.Connection it contains and thus causing later calls to try to reconnect and for whatever reason, reconnect always fails.
My question is why is the Connection object closed in the first place?