本文介紹了如何在 Java 中將日歷轉(zhuǎn)換為 java.sql.Date?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
限時送ChatGPT賬號..
Calendar cal;
String sql = "INSERT INTO ttable (dt) values (?);"
//dt is a dateTime field in ttable
PreparedStatement stmt = connection.prepareStatement(sql);
stmt = setDate(1,cal); //not working
stmt.execute();
stmt.close();
我想將 cal 轉(zhuǎn)換為 Date 類型以插入到表格中.
I would like to convert cal to a Date type to insert into table.
推薦答案
有一個getTime()
方法(不確定為什么不叫 getDate).
There is a getTime()
method (unsure why it's not called getDate).
剛剛意識到您需要一個 java.sql.Date.使用 cal.getTimeInMillis()
的答案之一就是您所需要的.
Just realized you need a java.sql.Date. One of the answers which use cal.getTimeInMillis()
is what you need.
這篇關(guān)于如何在 Java 中將日歷轉(zhuǎn)換為 java.sql.Date?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!