How to insert the data from text file into oracle table ?
Hi,
I want to read the data from text file and insert the data into oracle table.
I was try but i am not able to get the clear idea..! Please Help Me I need your help to solve the problem.
My text file shows like this (input.txt)
1190$$Viswanath Muthu$$23/08/2006$$00:55$$00:00:48
1192$$Balakrishnan H$$23/08/2006$$05:47$$00:32:56
This is my oracle table structure :
Ecode
Name
Date
Time
Duration
Thanks
Merlin Roshina
..and your question is?
kajbja at 2007-7-14 22:00:20 >

Well he is Merlin. Obviously magic is supposed to happen.
How to insert the date from that text file into oracle table..?Thanks,Merlin Roshina
> How to insert the date from that text file into> oracle table..?Do you have a specific question? We won't write the app for you.Kaj
kajbja at 2007-7-14 22:00:20 >

Steps to follow:1. Read the file2. Hold the value from the file in variables.3. Get DB connection.4. execute the SQL
I do a little for you, and you do the rest...
import java.io.*;
import java.util.*;
public class Example2 {
public static void main(String[] args) {
try {
BufferedReader in = new BufferedReader(new FileReader("D:\\PRUEBAS\\resources\\input.txt"));
String line;
StringTokenizer st;
String ecode;
String name;
String date;
String time;
String duration;
while ((line = in.readLine()) != null) {
try {
st = new StringTokenizer(line, "$$");
ecode = st.nextToken();
name = st.nextToken();
date = st.nextToken();
time = st.nextToken();
duration = st.nextToken();
// Here goes the insertion stuff
System.out.println("Here goes the insertion of the record...");
System.out.println(ecode + "," + name + "," + date + "," + time + "," + duration);
} catch (Exception e) {
// do nothing
}
}
in.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
(please, dont forget the ddollars. Its important for us)
JLuisa at 2007-7-14 22:00:20 >

> I do a little for you, and you do the rest...
>
> > import java.io.*;
> import java.util.*;
>
> public class Example2 {
>
> public static void main(String[] args) {
> try {
> BufferedReader in = new BufferedReader(new
> new
> FileReader("D:\\PRUEBAS\\resources\\input.txt"));
>
> String line;
> StringTokenizer st;
>
> String ecode;
> String name;
> String date;
> String time;
> String duration;
>
> while ((line = in.readLine()) != null) {
> try {
> st = new StringTokenizer(line, "$$");
> ecode = st.nextToken();
> name = st.nextToken();
> date = st.nextToken();
> time = st.nextToken();
> duration = st.nextToken();
>
> // Here goes the insertion stuff
> System.out.println("Here goes the insertion of
> on of the record...");
> System.out.println(ecode + "," + name + "," +
> "," + date + "," + time + "," + duration);
> } catch (Exception e) {
> // do nothing
> }
> }
>
> in.close();
>
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
>
> }
>
>
> (please, dont forget the ddollars. Its important for
> us)
Do you think this will help the OP in the long run?
> Do you think this will help the OP in the long run?
I especially like this part:
} catch (Exception e) {
// do nothing
}
Kaj
kajbja at 2007-7-14 22:00:20 >

> > Do you think this will help the OP in the long
> run?
>
> I especially like this part:
>
> > } catch (Exception e) {
> // do nothing
> }
>
>
> Kaj
Isnt that the greatest part of the code. People just catch the exception
and do nothing-and the next thing you will see on the forum will be: My code compiles run but it doesnt work.
I dont get exceptions. whats wrong with my code.
Hi JLuis,
Great !! its working fine... ! Thanks
But i have N number of lines in the text file..! I m trying to read the content from the text file..its through NoSuchElementException in
line of*
while ((lines = inn.readLine()) != null) {
st = new StringTokenizer(lines, "$$");
* code=st.nextToken() "
I am trying to find the solution..
if you have any idea please tell me..ASAP.
Thanks
Merlin Roshina
So what's keeping you from reading the API docs to find possible causes?
> I do a little for you, and you do the rest...
It doesn't work this way, if you do anything for them, they just come back and whine that the code provided doesn't work. Now, if you pointed the OP in the direction of the APIs that you covered instead, then he might actually learn something.
> (please, dont forget the ddollars. Its important for
> us)
Who the hell is "us" You better not be counting me in this.
I know its better for the person to find the answers themselves with a little digging but sometimes the API's are a ltille obscur and the code you find on the net just doesn't make sense. I'm not condoning writing the app for someone but once you have a working example sometimes the rest of the app falls into place. It has happened with me where the help I recieved from the forum has helped learn new things because I never even knew they existed.
> I know its better for the person to find the answers
> themselves with a little digging but sometimes the
> API's are a ltille obscur and the code you find on
> the net just doesn't make sense. I'm not condoning
> writing the app for someone but once you have a
> working example sometimes the rest of the app falls
> into place. It has happened with me where the help I
> recieved from the forum has helped learn new things
> because I never even knew they existed.
Your post implies, that the OP did search for code on the net and has looked at the APIs. He didn't. Otherwise he had posted the non working code and exact questions about unclear parts of the API.
Hi All,Thanks to All Java Mem..spce who is reply to my post.. !My application is working fine with the help of God and u ! ...!Thanks ,Merlin Roshina
This is because you have in your file, some lines that doesnt agree strictly with the format:
ecode$$name$$date$$time$$duration
confirm that with:
} catch (NoSuchElementException e) {
System.out.println("Line not well formed: " + line);
}
JLuisa at 2007-7-21 10:21:40 >
