[KLUG Members] Looking for JDBC data import utility

Bert members@kalamazoolinux.org
Wed, 21 May 2003 08:57:53 +0200


Adam Tauno Williams wrote:

>We were using IBM AGS Server Studio here until our trial license ran
>out.  Very nice app, but at $849 a seat it is a little steep (cough).
>
>So now that it stopped working I went scrounging about for a JDBC data
>manipulation program and found - http://www.minq.se/products/dbvis/
>It is a very good and solid program (actually crashes less often than
>the AGS product, which was really rare).    Actually it does a couple of
>things AGS didn't, such as on-the-fly resorting of query results and
>error messages that usually go so far as to indicate the real source of
>a problem (SHOCK!).
>
>But what it lacks is a data import feature,  which our QC guys *LOVED*
>in the AGS product.  You could match file columns (delimited) to data
>base fields with a nifty wizard, etc...
>
>Now something like that just has to have been written and lying out
>there somewhere.  If anyone can point me at some URL I'd appreciate it.
>
>We strongly prefer a JDBC based product as the ODBC Win32 drivers for
>real databases are a royal disaster, and being JAVA they can run the
>same app anywhere on anything.
>
>_______________________________________________
>Members mailing list
>Members@kalamazoolinux.org
>
>
>  
>
Adam, I agree that something like take should have been written already, 
but I don't no either where to find it.
I suppose you can write your self. I looked around and if maybe you can 
use the following piece of code I found as a starting point.

<SNIP>
A file containing the following data:

    135   7512   3659814  328   1 54829
    68522 19982810  38 

i.e. lines contain several ASCII strings that are numbers separated by 
spaces.
The code fragment is as follows:

//  Open the file with    
RandomAccessFile f = new RandomAccessFile("c:\\work\\datafile.txt", "r");

// read an entire line from it
String s= f.readLine();

// get some methods to break up a line into tokens
StringTokenizer st = new StringTokenizer(s);

// extract the next int from the line
i = Integer.parseInt(st.nextToken());

We use a RandomAccessFile because that supports the readLine() method 
directly. An alternative would be to instantiate a FileReader, and wrap 
a BufferedReader around it. Putting it all together, including the 
exception handling in the event the file is missing, the code looks like:


import java.io.*;
import java.util.*;
public class c  {
    public static void main(String args[]) {
      try {
        RandomAccessFile f = new RandomAccessFile
                                        ("datafile.txt", "r");
        String s;
        while ( (s=f.readLine()) != null )  {
            System.out.println("read: "+s);

            StringTokenizer st = new StringTokenizer(s);
            int i=0;
            while (st.hasMoreTokens()) {
               i = Integer.parseInt(st.nextToken());
               // i now holds the next int on the line
               // could also use Double.parseDouble(), etc.

               System.out.print(" "+ i);

		// <insert here your code to insert the data into you database>
		            }
            System.out.println();
        }

      } catch (Exception e) {System.out.println("Excpn: "+e); }
      // file I/O, from book "Just Java" by Peter van der Linden
    }
}

</SNIP>


Bert