I'm currently trying to get specific information from a String containing SQL queries. These Strings can be as simple as a single simple SQL query to hundreds of complex queries.
What I'm looking for is a simple way to get the names of all the tables from the FROM statements. Could someone point me towards any tools or classes suited for handling SQL in Java?
For example:
SELECT
ITEM1, ITEM2
FROM
TABLE1,
TABLE2
ORDER BY
ITEM1
Now, the end goal would be to extract the table names from the FROM statement, and use them to create a query like this:
SELECT
SUM(COUNT)
FROM
(SELECT COUNT(*) AS COUNT FROM TABLE1
UNION ALL
SELECT COUNT(*) AS COUNT FROM TABLE2
)
AS ROWCOUNT;
If I had the table names as strings, it would be fairly simple to wrap them in the subqueries. From that we'd be able to get the total number of rows being returned by the database.