ucanaccess
ucanaccess copied to clipboard
Can't insert into database
I've created an internally used tool that reads some records from a csv file, and then inserts them into an access database. This was working before, but when I switched to using the forked version of ucanaccess (5.1.1), the data is no longer inserted. I don't see any errors, but afterwards, when I open the file in Access, the data isn't there.
This is the code I'm running:
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
try (Connection connection = DriverManager.getConnection(connectionString);
PreparedStatement preparedStatement = connection.prepareStatement(SQL_STATEMENT)) {
List<Transaction> transactionList = InputFileParser.parseInputFile(this.importFilePath);
for (Transaction transaction : transactionList) {
preparedStatement.setInt(1, transaction.getFamilyId());
preparedStatement.setNull(2, Types.INTEGER);
preparedStatement.setDate(3, Date.valueOf(transaction.getDonationDate()));
preparedStatement.setDate(4, Date.valueOf(transaction.getDonationDate()));
preparedStatement.setString(5, Transaction.DONATION_TYPE);
preparedStatement.setBigDecimal(6, transaction.getAmount());
preparedStatement.setString(7, Transaction.DESIGNATION);
final int rows = preparedStatement.executeUpdate();
connection.commit();
log.info("Updated: {} row(s)", rows);
importResult.incrementCount(rows);
importResult.incrementTotalAmount(transaction.getAmount());
this.updateMessage("Inserted: %s\n".formatted(transaction.toString()));
log.info("Inserted: {}", transaction);
Thread.sleep(100);
}
} catch (final SQLException sqlException) {
log.warn("Error inserting transactions to database.", sqlException);
throw sqlException;
}
The connection string is: "jdbc:ucanaccess://V:\DevProj\psaft-importer\src\test\resources\database\test\test.accdb"
The SQL statement used in the prepared statement is:
INSERT INTO `Donation Detail` (`Donor_ID`, `Batch`, `Donation Date`, `Deposit Date`, `Donation Type`, `Amount`, `Designation`) VALUES (?, ?, ?, ?, ?, ?, ?)
If I switch back to the 'old' ucanaccess (5.0.1) from net.sf.ucanaccess
, the inserts work.
In case it helps, I'm using Java 22, and the UI for the tool is JavaFX (also version 22)
Any help would be appreciated.