import java.io.FileReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import au.com.bytecode.opencsv.CSVReader;
public class ImportingDate {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try{
/* Create Connection objects */
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn= DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521/xe","SYSTEM","sandp");
/* Create the insert statement */
String insertQuery = "Insert into date_tab(workdate) values(to_date(?,'dd/mon/yyyy hh24:mi:ss'))";
PreparedStatement pstmt = conn.prepareStatement(insertQuery);
CSVReader reader = new CSVReader(new FileReader("D:\\datedata.csv"), ',');
String[] nextLine;
int i = 0;
while((nextLine = reader.readNext()) != null)
{
i++;
if (nextLine.length == 1){
pstmt.setString(1,nextLine[0]);
i=pstmt.executeUpdate();
}
}
System.out.println("Data Successfully Uploaded");
pstmt.close();
conn.commit();
conn.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
i am getting an error as follows=
java.sql.SQLException: ORA-01843: not a valid month
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:955)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1169)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3285)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3368)
at a.ba.ImportingDate.main(ImportingDate.java:32)
i m using eclipse and oracle 10g how can i fix the problem and insert into table into timestamp datatype. i have created a table named date_tab(workdate timestamp)
CSV file contains as follows= 15-02-15 17:54:45
18-02-15 18:19:33
20-06-15 18:38:56
23-09-15 19:00:18
22-02-15 19:21:08
26-07-15 19:40:04
21-05-15 20:03:07
25-01-15 20:25:59
28-02-15 20:48:12
27-04-15 00:05:11
to_datestatement is not the same as the format of the dates in your CSV file.