我创建了一个表:
创建表约会(
App_ID号主键,
医生_ID号码,
Patient_ID 号,
应用程序_日期日期,
应用程序_时间时间戳,
App_Charges 编号);
我知道如何将字符串转换为java.sql.Date。 但现在我正在做
String s1=time.getSelelctedItem().toString();//specifying time from a combo box
然后
st.setString(5,s1);
请告诉我需要做出的改变.. 谢谢。
最佳答案
我会在中间使用java.util.Date
:
// Specifying time from a combo box
String s1 = time.getSelelctedItem().toString();
// Convert String to Date according to the format
SimpleDateFormat df = new SimpleDateFormat("hh:mm");
Date date = df.parse(s1);
// Convert Date to Timestamp
Timestamp ts = new Timestamp(date.getTime());
// Set it:
st.setTimestamp(5, ts);
关于java - 将字符串转换为 TIMESTAMP 以在表中插入时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22728343/