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

[505 byte] By [MerlinRosinaa] at [2007-10-3 4:01:09]
# 1
..and your question is?
kajbja at 2007-7-14 22:00:20 > top of Java-index,Java Essentials,Java Programming...
# 2
Well he is Merlin. Obviously magic is supposed to happen.
floundera at 2007-7-14 22:00:20 > top of Java-index,Java Essentials,Java Programming...
# 3
How to insert the date from that text file into oracle table..?Thanks,Merlin Roshina
MerlinRosinaa at 2007-7-14 22:00:20 > top of Java-index,Java Essentials,Java Programming...
# 4
> 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 > top of Java-index,Java Essentials,Java Programming...
# 5
Steps to follow:1. Read the file2. Hold the value from the file in variables.3. Get DB connection.4. execute the SQL
lupansanseia at 2007-7-14 22:00:20 > top of Java-index,Java Essentials,Java Programming...
# 6

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 > top of Java-index,Java Essentials,Java Programming...
# 7

> 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?

lupansanseia at 2007-7-14 22:00:20 > top of Java-index,Java Essentials,Java Programming...
# 8

> 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 > top of Java-index,Java Essentials,Java Programming...
# 9

> > 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.

lupansanseia at 2007-7-14 22:00:20 > top of Java-index,Java Essentials,Java Programming...
# 10

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

MerlinRosinaa at 2007-7-14 22:00:20 > top of Java-index,Java Essentials,Java Programming...
# 11
So what's keeping you from reading the API docs to find possible causes?
CeciNEstPasUnProgrammeura at 2007-7-14 22:00:20 > top of Java-index,Java Essentials,Java Programming...
# 12

> 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.

macrules2a at 2007-7-14 22:00:20 > top of Java-index,Java Essentials,Java Programming...
# 13

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.

tarmenela at 2007-7-14 22:00:20 > top of Java-index,Java Essentials,Java Programming...
# 14

> 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.

PhHeina at 2007-7-14 22:00:20 > top of Java-index,Java Essentials,Java Programming...
# 15
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
MerlinRosinaa at 2007-7-21 10:21:40 > top of Java-index,Java Essentials,Java Programming...
# 16

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 > top of Java-index,Java Essentials,Java Programming...