Syntax analysis of SQL query

465 views Asked by At

I'm creating a database wrapper in Java and I want it to analyze a sql query and determine the type of query. Is this possible or out there exists a library for this?

I'm doing it like this:

DB db = new DB();
db.execute(String query, String... params);

Then I execute the query using PreparedStatement.

So there a queries where I don't need the params. I want to write a general method for all queries.

1

There are 1 answers

1
Phil Anderson On

It weems to me that if you just want to work out whether the statement is a prepared statement or not, then you ought to be able to just parse the string looking for a ? that's not in-between quotes.

If there is, then it's a prepared statement.

My question to you is - If it is a prepared statement, how will you know what parameters to pass?