This connection class
public class AppConnect {
private static final String url ="jdbc:hsqldb:file:src/main/resources/db/library";
private static final String driver ="org.hsqldb.jdbcDriver";
private static final String user = "SA";
private static final String password = "";
public Connection getConnection() {
Connection connection = null;
try {
Class.forName(driver);
connection = DriverManager.getConnection(url, user, password);
connection.setAutoCommit(true);
System.out.println("+)");
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
System.out.println(":(");
}
return connection;
}
} This kinda insert method
public class AuthorSQL extends AppConnect implements AuthorsDAO {
Connection connection = getConnection();
@Override
public void add(Author author) throws SQLException {
PreparedStatement pr = null;
String sql = "INSERT INTO AUTHORS(ID, NAME, SURNAME, FATHERNAME) VALUES ( ?, ?, ?, ?)";
try {
System.out.println(connection.isClosed());
connection.setAutoCommit(true);
pr = connection.prepareStatement(sql);
pr.setLong(1, author.getId());
pr.setString(2, author.getName());
pr.setString(3, author.getSurname());
pr.setString(4, author.getFathername());
pr.executeUpdate();
connection.commit();
System.out.println("success");
} catch (SQLException e) {e.printStackTrace();
} finally {
pr.close();
connection.close();
}
}
Test shows all ok, request is passed, but in DB nothing new. getAll and getById(ResultSet) - methods works normal. DB in-memory. In the file properties of DB "only read" mode off.