csv into oracle using Java
807580Apr 20 2010 — edited Apr 21 2010Folks,
I see this topic handled several times over and over, yet I have a road block !
Here is the code that I wrote to load a csv file into Oracle 11, and I trying to use sqlldr. When I try to run this, its terminated without any error message and it doesnt write anything to the database either. Appreciate if anyone can provide some tips to debug this !
( and sqlldr is in the classpath)
<code>
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;
/*import oracle.jdbc.OracleDriver;*/
public class LoadAutosysRuntimes {
public static void main (String[] args){
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (Throwable t) {
t.printStackTrace();
System.err.println("Problem loading JDBC Drivers: "
+ t.getMessage());
System.exit(-1); // Terminate
}
String url = "jdbc:oracle:thin:@//orfny-dev2.intranet.xxx.com:1524/ORFNYD02";
try {
Connection conn = DriverManager.getConnection(url, "user", "pass");
conn.setAutoCommit(false);
// Create the statement
Statement stmt = conn.createStatement();
// Load the data
String filename = "C:\\Documents and Settings\\Desktop\\Metrics\\CCS_Daily_Job_Stats_test.csv";
String tablename = "TEST_AUTOSYS_DATA";
stmt.executeUpdate("LOAD DATA INFILE \"" + filename + "\" INTO TABLE "
+ tablename + " FIELDS TERMINATED BY ',' ");
} catch (SQLException e) {
}
}
}
</code>