This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes Read and Write .sql files using java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Read and Write .sql files using java" Watch "Read and Write .sql files using java" New topic

Read and Write .sql files using java

Manju Krishna
Ranch Hand

Joined: Apr 09, 2009
Posts: 48
I want to know if there are any freeware's available to read and write .sql files. I hava a .sql file with set of insert statements and I need to identify the values that are pushed into table, the table name, the inner query clauses etc., from the sql statement.

After identifying, need to translate and push those changes back to the .sql file. Is there any way to do this with help of parsers rather reading the whole of file line by line.

I did come across few parsers like ZQL, sqljep etc., but could not really solve the issue. Please help..
Thanks in advance.

Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3753

Is this a one-time use for yourself or part of an application you need to build? Stuff like this is often easier to write yourself in Java assuming the kinds of changes you need to be make can be made with regular expressions and the files you are reading are highly structured. The issue with 'generic' read/write tools is that every database has its own unique flavor of SQL and not all of them exactly match each other even on some basic commands.

[OCA 8 Book] [Blog]
Manju Krishna
Ranch Hand

Joined: Apr 09, 2009
Posts: 48
Say I have a line like below,

These statements gets repeated in the file consecutively. I need to get the insert column values (like user_id, module_id etc.,) and values that are inserted into the table (like 'LANGUAGE', 'L','system_preferences' etc., ) into any data structure. And also replace the values with translated values in same positions in writing back the values.
I agree. Here's the link:
subject: Read and Write .sql files using java
It's not a secret anymore!