我在 JSP 中创建了一个投诉注册表,其中有一个“时间”类型的输入字段,时间也不应该总是当前时间,因此我不能使用 SQL 的 CURRENTTIME() 方法。现在,在将它分配给数据库时,我收到 HTTP 状态 500 – 内部服务器错误,因为“检查与您的 MySQL 服务器版本相对应的手册,以获取在 '.'20:20:00') 附近使用的正确语法”在第 1 行”。这里我使用了“setString()”方法。我已经尝试过 setTime() 但这在这里也不起作用,而 setString() 正在为日期值工作并且日期正确插入到数据库中。*/这是我的jsp代码,用于在“PCS”数据库的“test”表中插入时间。<%@ page import="java.sql.*" %> String time=request.getParameter("time");String url="jdbc:mysql://localhost:3306/pcs";String uname="root";String passw="publiccomplaint";String query="insert into test values(?)";Class.forName("com.mysql.jdbc.Driver");Connection con=DriverManager.getConnection(url,uname,passw);PreparedStatement st=con.prepareStatement(query);st.setString(1,time); int count=st.executeUpdate();st.close();con.close();从表单的输入 type="time" 字段将时间插入 MYSQL DB 的正确方法是什么?
3 回答
波斯汪
TA贡献1811条经验 获得超4个赞
你可以这样试试
String time = "15:30:18";
DateFormat sdf = new SimpleDateFormat("hh:mm:ss");
Date date = sdf.parse(time);
System.out.println("Time: " + sdf.format(date));
添加回答
举报
0/150
提交
取消