当我尝试执行以下代码时,它给了我一个java.sql.SQLException: ORA-01861: literal does not match format string
错误。
我正在尝试将一些列值从customer1_details
表复制到customer2_details
表。我要移动的列数据类型是TIMESTAMP(6)
for TIME_REGISTERED
, DATE_DISCHARGED
columns 和DATE_OF_BIRTH
column 的数据类型是DATE
try
{
Connection conn=Address.getOracleConnection();
int id = 1;
Date dob = null;
Timestamp timereg = null,datedischarged = null;
Statement stmt=conn.createStatement();
ResultSet res=stmt.executeQuery("SELECT TIME_REGISTERED,DATE_DISCHARGED,DATE_OF_BIRTH from customer1_details WHERE customer_id = '"+id+"' ");
if(res.next())
{
timereg=res.getTimestamp("TIME_REGISTERED");
datedischarged=res.getTimestamp("DATE_DISCHARGED");
dob=res.getDate("DATE_OF_BIRTH");
}
String sql1="INSERT INTO customer2_details(TIME_REGISTERED_3,DATE_DISCHARGED_3,DATE_OF_BIRTH,customer_ID) "
+ "VALUES('"+timereg+"','"+datedischarged+"','"+dob+"','"+id+"') ";
PreparedStatement pst=conn.prepareStatement(sql1);
pst.executeUpdate();
pst.close();
conn.close();
}
catch(Exception e)
{ System.out.print(e); }
如果有人提供答案会更有帮助without using INSERT INTO ... SELECT ... statement
。