【发布时间】:2013-03-29 14:14:56
【问题描述】:
我正在从安卓设备发送到服务器字符串sysdate()。问题是代码没有向 mysql 数据库插入任何内容。 first 列是 DATETIME。我正在使用 mysql 工作台,当我在工作台中输入INSERT INTO test (first) VALUES (sysdate()); 时,它可以工作。
<%
String t = request.getParameter("time");
Connection connection = null;
PreparedStatement pstatement = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
int updateQuery = 0;
if (t != null) {
if (t != "" ) {
try {
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
Statement st = connection.createStatement();
String queryString1 = "INSERT INTO test (first) VALUES (?)";
pstatement = connection.prepareStatement(queryString1);
pstatement.setString(1, t);
updateQuery = pstatement.executeUpdate();
if (updateQuery != 0) {
response.setStatus(400);
}
} catch (Exception ex) {
out.println(ex);
} finally {
pstatement.close();
connection.close();
}
}
}
%>
【问题讨论】:
-
来自 Android 的日期是什么样的?换句话说,你的变量
t的值是多少?是3/29/2013吗?2013-03-29?另外,您是否真的有一个控制台来查看在您的catch中输出的异常?你可以检查一下。 -
看起来像
sysdate()。我不转换它...
标签: mysql jsp prepared-statement sysdate