Я практикую JDBC пакетную обработку и содержащие ошибки:Пакетная обработка JDBC
ошибки 1: неподдерживаемый функция Ошибка 2: Выполнить не может быть пустым или нулевым
Property files include:
itemsdao.updateBookName = Update Books set bookname = ? where books.id = ?
itemsdao.updateAuthorName = Update books set authorname = ? where books.id = ?
Я знаю, что могу выполнить около заявления DML в одном обновлении, но я занимаюсь пакетной обработкой в JDBC.
Ниже мой метод
public void update(Item item) {
String query = null;
try {
connection = DbConnector.getConnection();
property = SqlPropertiesLoader.getProperties("dml.properties");
connection.setAutoCommit(false);
if (property == null)
{
Logging.log.debug("dml.properties does not exist. Check property loader or file name is spelled right");
return;
}
query = property.getProperty("itemsdao.updateBookName");
statement = connection.prepareStatement(query);
statement.setString(1, item.getBookName());
statement.setInt(2, item.getId());
statement.addBatch(query);
query = property.getProperty("itemsdao.updateAuthorName");
statement = connection.prepareStatement(query);
statement.setString(1, item.getAuthorName());
statement.setInt(2, item.getId());
statement.addBatch(query);
statement.executeBatch();
connection.commit();
}catch (ClassNotFoundException e) {
Logging.log.error("Connection class does not exist", e);
}
catch (SQLException e) {
Logging.log.error("Violating PK constraint",e);
}
//helper class th
finally {
DbUtil.close(connection);
DbUtil.closePreparedStatement(statement);
}
Вы отправили всю ошибку? –
поддерживает ли ваш jdbc драйвер/поддержка базы данных? – BevynQ
Вы хотите 'statement.addBatch()', а не 'statement.addBatch (query)'? – Glenn