@Test public void testForConnectionStateAfterBatchException() throws SQLException {
sql2o.createQuery("create table issue3table(id integer identity primary key, val varchar(5))").executeUpdate();
boolean failed = false;
Connection connection = sql2o.beginTransaction();
try{
connection.createQuery("insert into issue3table(val) values(:val)")
.addParameter("val", "abcde").addToBatch()
.addParameter("val", "abcdefg").addToBatch() // should fail
.addParameter("val", "hello").addToBatch()
.executeBatch().commit();
}
catch(Sql2oException ex){
failed = true;
System.out.println("expected exception occured, msg: " + ex.getMessage());
}
assertTrue(failed);
assertTrue("Assert that connection is correctly closed (with transaction)", connection.getJdbcConnection().isClosed() );
// same test, but not in a transaction
Query query = sql2o.createQuery("insert into issue3table(val) values(:val)")
.addParameter("val", "abcde").addToBatch()
.addParameter("val", "abcdefg").addToBatch() // should fail