Have a problem with dumping oracle table to csv file. Problem is in date dumping I get date like "23-Jun-2009" with current code, but I need something like "2009-06-23 20:18:44". I get right date date, if put code
while(result.next()) {
System.out.println(result.getString("D_FORM"));
}
I can not understand how and where dates are converted my code is
package com.my.table2csv;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.net.URL;
import java.sql.*;
import java.util.Calendar;
import java.util.Map;
import au.com.bytecode.opencsv.CSVWriter;
public class Main {
public static void main(String[] args) throws IOException, SQLException {
String host = "";
String user = "";
String password = "";
String db = "";
String table = "";
String file = "";
Connection conn = null;
for(int i=0; i < args.length; i++) {
if (args[i].equals("-h")) {
host = args[++i];
}
if (args[i].equals("-u")) {
user = args[++i];
}
if (args[i].equals("-p")) {
password = args[++i];
}
if (args[i].equals("-d")) {
db = args[++i];
}
if (args[i].equals("-t")) {
table = args[++i];
}
if (args[i].equals("-f")) {
file = args[++i];
}
}
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
conn = DriverManager.getConnection("jdbc:oracle:thin:@"+host+":1521:"+db, user, password);
conn.setAutoCommit(true);
String queryStr = "SELECT * FROM " + table;
PreparedStatement preStatementS = conn.prepareStatement(queryStr);
ResultSet result = preStatementS.executeQuery();
//while(result.next()) {
// System.out.println(result.getString("D_FORM"));
//}
CSVWriter writer = new CSVWriter(new FileWriter(file), ',');
writer.writeAll(result, `enter code here`false);
writer.close();
}
}
For an explanation see
http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-faq-090281.html#08_01
I solved the issue by adding
Onto my java command ine