Re: Vertica 6.0 and COPY LOCAL issue
Posted: Wed Jun 13, 2012 9:45 am
I do not use a Servlet but a simple java class.
The main method where the COPY LOCAL statement is executed :
private void loadData(java.sql.Connection connection) throws Exception {
//create the empty file
FileOutputStream out = new FileOutputStream(new File("/var/VERTICA_FLOW/rejected/VERTICA_FLOW8.txt"));
out.close();
String sql = "COPY public.TEST_LOAD_TABLE (A, B, DATADATE FORMAT 'YYYYMMDDHH24MISS', N) FROM LOCAL '/var/work/VERTICA_FLOW8.txt' DELIMITER '|' TRAILING NULLCOLS REJECTED DATA '/var/VERTICA_FLOW/rejected/VERTICA_FLOW8.txt' DIRECT NO COMMIT;";
try {
System.out.println("Executing statement : " + sql);
connection.setAutoCommit(false);
Statement stmt = connection.createStatement();
stmt.execute(sql);
long insertedRow = stmt.getUpdateCount();
System.out.println("Inserted rows : " + insertedRow);
} catch (Exception ex) {
connection.rollback();
throw ex;
}
connection.commit();
}
where java.sql.Connection is the connection to the Vertiva database obtained by :
public Connection createConnection(String username, String password, String connectionUrl) throws SQLException {
return java.sql.DriverManager.getConnection(connectionUrl, username, password);
}
Thanks in advance
The main method where the COPY LOCAL statement is executed :
private void loadData(java.sql.Connection connection) throws Exception {
//create the empty file
FileOutputStream out = new FileOutputStream(new File("/var/VERTICA_FLOW/rejected/VERTICA_FLOW8.txt"));
out.close();
String sql = "COPY public.TEST_LOAD_TABLE (A, B, DATADATE FORMAT 'YYYYMMDDHH24MISS', N) FROM LOCAL '/var/work/VERTICA_FLOW8.txt' DELIMITER '|' TRAILING NULLCOLS REJECTED DATA '/var/VERTICA_FLOW/rejected/VERTICA_FLOW8.txt' DIRECT NO COMMIT;";
try {
System.out.println("Executing statement : " + sql);
connection.setAutoCommit(false);
Statement stmt = connection.createStatement();
stmt.execute(sql);
long insertedRow = stmt.getUpdateCount();
System.out.println("Inserted rows : " + insertedRow);
} catch (Exception ex) {
connection.rollback();
throw ex;
}
connection.commit();
}
where java.sql.Connection is the connection to the Vertiva database obtained by :
public Connection createConnection(String username, String password, String connectionUrl) throws SQLException {
return java.sql.DriverManager.getConnection(connectionUrl, username, password);
}
Thanks in advance