我试图插入" 2016-07-24"使用JDBC,SimpleDateFormat类进入Oracle数据库。在数据库中,它应保存为" 24-JUL-16"而不是插入" 24-JUL-24" 这是一种不正确的格式。以下是我的代码。请让我知道SimpleDateFormat应该更改什么。
我怀疑是不是因为我还没有宣布
public static final SimpleDateFormat transDate = new SimpleDateFormat(
"yyyy-MM-dd");
瞬态。
import java.sql.Connection;
import java.sql.SQLException;
import com.myjdbc.database.DBConnection;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
public class DateInserter {
private static final String PROCEDURE_FOO = "{call P_PROCESS_FOO(?,?,?)}";
public static transient final SimpleDateFormat transBusinessDate = new SimpleDateFormat(
"yyyy-MM-dd");
public static final SimpleDateFormat transDate = new SimpleDateFormat(
"yyyy-MM-dd");
public static void callProcedure() throws SQLException {
Connection con = null;
CallableStatement stmt = null;
ResultSet jdbcRs = null;
try {
con = DBConnection.getConnection();
stmt = con.prepareCall(PROCEDURE_FOO);
stmt.setString("P_TRANS_ID", "A1221");
stmt.setDate("P_TRANS_BUSNS_DATE", new java.sql.Date(
transBusinessDate.parse("2016-07-31").getTime()));
stmt.setDate("P_TRANS_DT",
new java.sql.Date(transDate.parse("2016-07-30").getTime()));
stmt.execute();
jdbcRs = (java.sql.ResultSet) stmt.getObject("P_TRANS_DATA");
} catch (Exception e) {
System.out.println("JDBC Exception " + e);
}
}
}