org.enableit.db
Class DataLoader

java.lang.Object
  |
  +--org.enableit.db.DataLoader

public class DataLoader
extends java.lang.Object

A class to read CSV files and load data into a database.

Version:
v1.3
Author:
chris.pettifer@enableit.org

Field Summary
static java.lang.String about
          CVS info about this class and its current version
protected static org.apache.log4j.Category cat
          The Log4J Category doing the logging.
private  java.util.ArrayList columns
          The columns to load into.
private  java.lang.String dataSourceName
          The datasource name to use to get a database connection.
private  java.io.File file
          The file to read.
private  java.lang.String table
          The Table to load into.
 
Constructor Summary
DataLoader()
          Default Constructor
DataLoader(java.lang.String file)
          Constructor setting mandatory properties.
 
Method Summary
 void execute()
          Do the load.
static void main(java.lang.String[] args)
          Used as a simple test of the class.
private  void process(java.lang.String line)
          Processes a data line.
private  void processComment(java.lang.String line)
          Processes a comment line, looking for meta data.
 void setColumnDatatypes(java.lang.String datatypes)
          Set the datatypes of the columns to be inserted into.
 void setColumnNames(java.lang.String columns)
          Set the names of columns to be inserted into.
 void setDataSourceName(java.lang.String dataSourceName)
          Set the datasource name to get connections from.
 void setFile(java.io.File file)
          Set the file to be loaded.
 void setFile(java.lang.String file)
          Set the file to be loaded.
 void setTable(java.lang.String table)
          Set the file to be loaded.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

cat

protected static org.apache.log4j.Category cat
The Log4J Category doing the logging. Same Category is used throughout the package.

file

private java.io.File file
The file to read.

table

private java.lang.String table
The Table to load into.

columns

private java.util.ArrayList columns
The columns to load into.

dataSourceName

private java.lang.String dataSourceName
The datasource name to use to get a database connection.

about

public static final java.lang.String about
CVS info about this class and its current version
Constructor Detail

DataLoader

public DataLoader()
Default Constructor

DataLoader

public DataLoader(java.lang.String file)
Constructor setting mandatory properties.
Method Detail

setFile

public void setFile(java.io.File file)
Set the file to be loaded.

setFile

public void setFile(java.lang.String file)
Set the file to be loaded.

setTable

public void setTable(java.lang.String table)
Set the file to be loaded.
This field is not mandatory if metadat is supplied at the top of the CSV file.

setColumnNames

public void setColumnNames(java.lang.String columns)
Set the names of columns to be inserted into.
Parameters:
columns - as a comma separated list.

setColumnDatatypes

public void setColumnDatatypes(java.lang.String datatypes)
Set the datatypes of the columns to be inserted into.
Parameters:
columns - as a comma separated list.

setDataSourceName

public void setDataSourceName(java.lang.String dataSourceName)
Set the datasource name to get connections from.

execute

public void execute()
             throws java.io.IOException,
                    java.sql.SQLException
Do the load.

processComment

private void processComment(java.lang.String line)
Processes a comment line, looking for meta data.

process

private void process(java.lang.String line)
Processes a data line.

main

public static void main(java.lang.String[] args)
Used as a simple test of the class.


Copyright © enableIT.org 1999,2000,2001,2002 All Rights Reserved.