我正在尋找最好的方法來更新MySQL中的DateTime字段,而通過我的結果集。我發現了一些其他的問題,但沒有一個解決rs.updateDate語句中的Java數據和SQL日期格式。我附上了編輯正在嘲笑的代碼。在MySQL中爲DateTime列更新ResultSet列
public class EmailQueueProcess {
public static Boolean process()
{
Date processedDtm = new Date();
java.util.Date today=new java.util.Date();
Timestamp currentTimestamp=new Timestamp(today.getTime());
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
strSQL = "select * from portal.emailqueue where portal.emailqueue.processedDtm is null";
conn = com.retailapppartners.Utils.staticGetConnection().getConnection();
stmt = conn.prepareStatement(strSQL, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
//now loop through and update the process datetime values
rs = stmt.executeQuery();
ResultSetMetaData rsMetaData = (ResultSetMetaData) rs.getMetaData();
int numberOfColumns = rsMetaData.getColumnCount();
while (rs.next()) {
// Grab some data then update the row
rs.updateDate ("processedDtm", currentTimestamp);
rs.updateRow();
}
} catch .....
你有什麼錯誤?你的意思是什麼日期「格式」? –
編輯說:「ResultSet類型中的方法updateDate(String,Date)不適用於參數(String,Timestamp)」因此,看起來我的變量與rs.updateDate不兼容。 –
你好,歡迎來到Stack Overflow。請閱讀幫助中心的[如何創建最小,完整和可驗證示例](http://stackoverflow.com/help/mcve),然後相應地編輯您的問題。謝謝。 –