我正在尋找一種方法來獲取今天的日期並傳遞到SQL表並保存在那裏。調用保存的日期並使用JODA TIME API執行一些任務。該改變喬達時間日期到SQL表,並保存有和進程繼續..日期 - Java到Sql表和SQL表通過Joda時間到Java時間
我試過這種方式,
//prints todays date
java.sql.Date sqlDate = new java.sql.Date(new Date().getTime());
//passes wrong date to the table like 1970-07-01 instead of 2013-03-01
String insert = "INSERT INTO TEST_TABLE VALUES(1,"+sqlDate+")";
pStmt = conn.prepareStatement(insert);
pStmt.executeUpdate();
//converting to joda time
LocalDate ld = new LocalDate(sqlDate);
//some calculations, and how to convert back to sql date?
我想在這裏做的就是,一個表3列(ID,開始日期,finishdate)。 ID將由用戶輸入,開始日期應該自動輸入今天的日期。經過一些計算與喬達時間和完成日期將被設置爲日期完成。
代碼
String insert = "INSERT INTO TEST_TABLE VALUES(2,'"+timestamp+"')";
錯誤
Data type mismatch in criteria expression
//I have created table using MS access
//the format of the date column is Date/Time.
你見過此http://計算器。 com/questions/8992282/convert-localdate-to-localdatetime-or-java -sql-timestamp – Freak 2013-03-01 10:41:18
可能請查看底部更新的問題,我面臨錯誤,謝謝。 – vijay 2013-03-01 10:57:44
請正確使用準備好的語句(通過使用'?'代替您想要的參數,然後使用相應的'setX()'函數),您的PS在技術上仍然容易受到SQL注入的影響。 – Quetzalcoatl 2013-03-01 11:34:08