473,378 Members | 1,658 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Reading a SQL file in Java

Hello everyone,

Just wondering if someone could help me with this. I'm working on a JDBC assignment but cannot quite figure out how to read in the required file.

Some example lines are:

insert into Transactions (YY_MM_DD, HH_MM_SS, Kind, Account, Name, Street, Suburb, Postcode)
values ('07/02/20', '16:42:46', '(', 'S017', 'Strathfield Car Radios ', '689 South Road ', 'Black Forest SA ', 5035);
insert into Transactions (YY_MM_DD, HH_MM_SS, Kind, Account, Name, Street, Suburb, Postcode)
values ('07/02/20', '16:42:58', '(', 'S018', 'Strathfield Car Radios ', 'Kiosk 4 Westfield ', 'Kilkenny SA ', 5009);

How would I be able to save each value into a string so that I could use java code to execute queries? Since I have to apply it to a table called NewCustomers. If anyone wants me to post the question I will.

Thanks
May 11 '07 #1
6 7938
r035198x
13,262 8TB
Hello everyone,

Just wondering if someone could help me with this. I'm working on a JDBC assignment but cannot quite figure out how to read in the required file.

Some example lines are:

insert into Transactions (YY_MM_DD, HH_MM_SS, Kind, Account, Name, Street, Suburb, Postcode)
values ('07/02/20', '16:42:46', '(', 'S017', 'Strathfield Car Radios ', '689 South Road ', 'Black Forest SA ', 5035);
insert into Transactions (YY_MM_DD, HH_MM_SS, Kind, Account, Name, Street, Suburb, Postcode)
values ('07/02/20', '16:42:58', '(', 'S018', 'Strathfield Car Radios ', 'Kiosk 4 Westfield ', 'Kilkenny SA ', 5009);

How would I be able to save each value into a string so that I could use java code to execute queries? Since I have to apply it to a table called NewCustomers. If anyone wants me to post the question I will.

Thanks
You don't have to post the question. You can use Scanner or FileReader to read a file. Look them up.
May 11 '07 #2
dmjpro
2,476 2GB
a good thing u r doing.

also u need little bit of parsing the SQL statement ... not the same as ORACLE does it.

actually i telling u ... the start a nd end of a SQL statement ... u have to figure u first then u can seperately execute the code....right.

have a good day.
best of luck with ur approach.

kind regards.

dmjpro.
May 11 '07 #3
Oh ok I've read those but I can't seem to apply them to the file I'm reading. I'm trying to use a FileReader and Tokenizer to read the strings but I'm not sure on how to ignore the things I don't need.

For example I want to save the values of the attributes into strings so I can use them in a subsequent query. But one of the attributes, Kind, can have the value '(' but I'm not sure how to make the tokenizer ignore opening brackets except in kind.

i.e. I want the things in bold in a variable
insert into Transactions (YY_MM_DD, HH_MM_SS, Kind, Account, Name, Street, Suburb, Postcode)
values ('07/02/20', '16:42:46', '(', 'S017', 'Strathfield Car Radios ', '689 South Road ', 'Black Forest SA ', 5035);

Any hints would be greatly appreciated.
May 11 '07 #4
dmjpro
2,476 2GB
try to use a character seperator by which u can seperate each query.....because it is too difficult to parsing the SQL start and end point.

and mind it .... try to use that character that nerver occures in ur sql file except at the start and end point of each query.

then tokenize using this delimeter.

best of luck.
have a good day.

kind regards.
dmjpro.
May 11 '07 #5
r035198x
13,262 8TB
Oh ok I've read those but I can't seem to apply them to the file I'm reading. I'm trying to use a FileReader and Tokenizer to read the strings but I'm not sure on how to ignore the things I don't need.

For example I want to save the values of the attributes into strings so I can use them in a subsequent query. But one of the attributes, Kind, can have the value '(' but I'm not sure how to make the tokenizer ignore opening brackets except in kind.

i.e. I want the things in bold in a variable
insert into Transactions (YY_MM_DD, HH_MM_SS, Kind, Account, Name, Street, Suburb, Postcode)
values ('07/02/20', '16:42:46', '(', 'S017', 'Strathfield Car Radios ', '689 South Road ', 'Black Forest SA ', 5035);

Any hints would be greatly appreciated.
Are all the queries in this format or do you have a file with lots of queries with different structures?
May 11 '07 #6
Are all the queries in this format or do you have a file with lots of queries with different structures?
They are different structures which I think is determined by the 'Kind' (transaction type) value.

For example:

'Opening Account' kind:

insert into Transactions (YY_MM_DD, HH_MM_SS, Kind, Account, Name, Street, Suburb, Postcode)
values ('07/02/20', '16:42:46', '(', 'S017', 'Strathfield Car Radios ', '689 South Road ', 'Black Forest SA ', 5035);

'Closing Account' kind:
insert into Transactions (YY_MM_DD, HH_MM_SS, Kind, Account)
values ('07/02/20', '16:44:50', ')', 'D005');

'Orders' kind:
insert into Transactions (YY_MM_DD, HH_MM_SS, Kind, Account, Item_No, Qty_Ordered)
values ('07/02/20', '16:46:04', '>', 'G015', 'SANDRC', 1);

Once I can get the 'Kind' value (transaction type) I should be able to figure out what to do with the other values.

Well I'll try and do what dmjpro suggested, hopefully I can figure it out ehehe

Thanks guys
May 11 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Sivaraj G via .NET 247 | last post by:
We created a unicode file using java application. It usesmethods like writeUTF(), writeInt() of java.io.DataOutputStreamclass to write the content of the file. We are able to read datausing...
4
by: Fazana | last post by:
I need help for reading a text file into in my java program. The file contains this information: ID# Student’s Answers --------------------------- 236499 TFTFTFTFFFFTFTFFFTF 643828...
0
by: EPDJ | last post by:
Well, I have to edit a program which we previously used for reading a header file to be able to read a trailer from a .dat file. The .dat file consists of 5 entries in each record and I am assuming...
19
by: r035198x | last post by:
The program below simply reads a file called FileTest1.java(itself) and prints it to the console import java.util.Scanner; import java.io.*; class FileTest1 { public static void...
5
blazedaces
by: blazedaces | last post by:
Ok, so you know my problem, java is running out of memory reading with SAX, the event-based xml parser intended more-so than DOM for extremely large files. I'll try to explain what I've been doing...
7
madhoriya22
by: madhoriya22 | last post by:
Hi, I am trying to read a file sent from client to server. Here is how I am trying it .... String filePath = request.getParameter("SelectCSVFile"); System.out.println("path:::---> "+filePath);...
7
by: tackleberi | last post by:
hi, im having some trouble reading a file into java and then storing it in an array here the code i have so far: import java.io.FileNotFoundException; import java.io.FileReader; import...
1
by: CodeSeeker | last post by:
I have an application, which uses pop3 to read the messages from the mailbox, and it has been working fine for so many year. We recently have started changing this application to use java mail IMAP 4...
4
by: lilyumestar | last post by:
I have project I have to do for class. We have to write 4 different .java files. Project2.java HouseGUI.java House.java HouseSorting.java I already finish House.java and I need to work on...
20
by: cowboyrocks2009 | last post by:
Hi, I need help to automate my code to take data from input file. Also I need to create it as a function so that I can pass it to some other program. I am new to Java so having a bit limitation to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.