gpt4 book ai didi

SQL处理中的Java BatchUpdateException

转载 作者:太空宇宙 更新时间:2023-11-03 11:07:55 25 4
gpt4 key购买 nike

下面的代码给出了一个BatchUpdateException,我不知道为什么。

public void createContactmoment(Document document) {
try {
c = MySqlDAOFactory.getInstance().getConnection();
//
c.setAutoCommit(false);
//
String sql = "insert into index(iddocument,chapter,chapterdate)"
+ "values (?,?,?)";
//
prest = c.prepareStatement(sql);
//
int count = 1;
//Formatter for the time
DateTimeFormatter format = DateTimeFormat.forPattern("dd-MM-yyyy");
//
while (count <= Integer.parseInt(document.getTeachingWeeks())
|| count == document.getAllDates().size()
|| count == document.getContactMomentList().size()) {
//
if (MysqlDocumentDAO.getInstance().findByName(
document.getName()) == -1)
return;
//
prest.setInt(1,MysqlDocumentDAO.getInstance().findByName(
document.getName()));
if (document.getContactMomentList().get(count) != null)
prest.setString(2,document.getContactMomentList().get(count));
else
prest.setString(2, "No contactmoment found, but expected");
//
if (document.getAllDates().get(count) != null)
prest.setString(3,(format.print(document.getAllDates().get(count))));
else
prest.setString(3, "Na date found, but expected");
//
prest.addBatch();
//
count++;
}
//
prest.executeBatch();
c.commit();
//
} catch (SQLException e) {
JdbcLogging.info("Dit trad op bij het uitvoeren van de batchtaak (contactMoments)"+ " :" + e);
} finally {
MySqlConnectionFactory.getInstance().closeStatement(prest);
MySqlConnectionFactory.getInstance().closeConnection(c);
}
}

我在日志中看到的错误是:

INFO JdbcLogging:25 - Dit trad op bij het uitvoeren van de batchtaak (contactMoments) :java.sql.BatchUpdateException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'index(iddocument,chapter,chapterdate)values (44,'Examen; * Verdedigen project','' at line 1

看来在上次更新中我遗漏了一些数据。我要写入的数据确实存在(我用系统打印行检查过。

欢迎提出任何建议。

最佳答案

index 是一个保留字,不应该用于表名。在您的查询中,将单词 `index` 放在 `back quotes` 中并执行,然后它应该可以正常工作。

String sql = "insert into `index`(iddocument,chapter,chapterdate) values (?,?,?)";

关于SQL处理中的Java BatchUpdateException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10600838/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com