我想在Access中插入日期时间值,但是我收到此错误:
net.ucanaccess.jdbc.UcanaccessSQLException:UCAExc ::: 3.0.4数据异常:日期时间格式无效
以下是代码:
private void txtsubmitActionPerformed(java.awt.event.ActionEvent evt) {
SimpleDateFormat A = new SimpleDateFormat("dd/MM/yyyy");
Peminjaman P= new Peminjaman(setIDTrans(),txtid.getText(),A.format(txttglpinjam.getDate()),A.format(txttglkembali.getDate()),txtplat.getText(),txtnama.getText(),txtdriver.getText());
c.InsertPeminjamanD(P);
答案 0 :(得分:3)
错误消息表明您的<html>
<head>
<meta charset="utf-8">
</head>
<body>
<tr>
<td><input type='text'></td>
<td><button class='clk' onclick="g(this)">click me!</button></td>
</tr>
<script src="jquery/jquery.min.js"></script>
<script>
function g(c) {
alert(c.parentNode.nodeName);
}
</script>
</body>
</html>
方法最终尝试执行类似
InsertPeminjamanD
并且由于两个原因而无法工作:
UCanAccess期望将日期文字括在哈希标记(INSERT INTO Table1 (DateTimeField) VALUES ('31/05/2016')
)和
UCanAccess通常希望#
日期文字为xx/yy/zzzz
,而不是MM/dd/yyyy
。
因此,如果将上面的查询重新排列为...
,则上述查询将起作用dd/MM/yyyy
...虽然最好使用PreparedStatement并将其传递给正确的日期值:
INSERT INTO Table1 (DateTimeField) VALUES (#05/31/2016#)