java - 将字符串转换为 TIMESTAMP 以在表中插入时间?

标签 java jdbc

我创建了一个表:

创建表约会( 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/

相关文章:

java - 一般如何从 ResultSet 中获取值?

java - JDBC MySQL 编辑/更新数据库中的当前条目

java - 使用 SQL Server 2005/2008 的最新 jdbc 驱动程序时,准备好的语句、 View 和存储过程的性能比较如何?

java - 映射两个不同大小的ArrayList

java - 在 java 中声明 byte[]?

java - 'nameList' 变量是实例变量还是类变量?为什么不包含在 'synchronised(this){}"语句中呢?

mysql - Windows 8.1 64 位 Tomcat 7.0.53 上的 BIRT 4.3.2 给出错误 'Cannot open the connection for the driver: org.eclipse.birt.report.data.oda.jdbc. '

java - 在 Spring Boot 中使用 @autowire 注释抛出 'BeanCreationException'

java - Java 书中的嵌套 do-while 和 System.in.read() 示例

jdbc - Kafka Connect、JDBC 连接器明文密码。如何避免?