Hello everybody,
I am newbie in java. I tried to create such a data pipe line that copy tables from 1 source to different servers & databases. It work fine with String and Number, but I stuck in Date datatype. I got Exception in thread "main" java.sql.SQLException: ORA-01843: not a valid month.
I have no idea how to change the date format in java or work with date data type.
Here the detail : Oracle 10g (Svr1) & 11g (Svr2), java 8 with ojdbc14.jar
The table's DB
Table = LAB
field = ID(INT), LAB_DESC(VARCHAR2, 50), LAB_DATE(DATE)
The Java Code
//========= Bismillah Arrahman Arrahiem =============//
//============== DARI SINI ========================================//
// ** ** ** **
// **** ** ** ** **** ** ** ** **
// **** ** ** ** * * ** ** ** **
// ********** ** ****************************
// *
//
//========================= LAB =============================//
package simpledtpipeline;
import java.sql.*;
public class SimpleDTpipeline {
public static void main(String[] args)
//========= Bismillah =============//
throws SQLException, ClassNotFoundException, Exception {
// Load the JDBC driver
Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println("Driver loaded");
//======================================================//
// Connect to a database
Connection connectionServer1 = DriverManager.getConnection
("jdbc:oracle:thin:@192.168.7.1:1521:dbone", "user", "pass123");
System.out.println("Database 192.168.7.1 connected");
//======================================================//
Connection connectionServer2 = DriverManager.getConnection
("jdbc:oracle:thin:@192.168.7.2:1521:dbtwo", "user2", "pass789");
System.out.println("Database 192.168.7.2 connected");
//
//========================= LAB =============================//
Statement SelectLAB = connectionServer1.createStatement();
// Execute a statement
ResultSet FetchLAB = SelectLAB.executeQuery
("SELECT ID, LAB_DESC, LAB_DATE from LAB ");
//*****************************************************************//
PreparedStatement InsertLAB = connectionServer2.prepareStatement("INSERT INTO LAB "
+ "(ID, LAB_DESC, LAB_DATE) VALUES (?,?, TO_DATE(?,'MM/DD/YYYY')");
while (FetchLAB.next()){
InsertLAB.setInt(1,FetchLAB.getInt("ID"));
InsertLAB.setString(2,FetchLAB.getString("LAB_DESC"));
InsertLAB.setString(3,FetchLAB.getString("LAB_DATE"));
InsertLAB.execute();
}
//======================================================//
//
// Close the connection //
connectionServer1.close();
connectionServer2.close();
}
}