Skip to content
This repository has been archived by the owner on Jan 5, 2023. It is now read-only.

Commit

Permalink
Add PreparedStatament to Simple Batch Test
Browse files Browse the repository at this point in the history
  • Loading branch information
vladmihalcea committed Jul 23, 2015
1 parent 635fdcb commit a3c1e3a
Showing 1 changed file with 28 additions and 1 deletion.
Expand Up @@ -3,6 +3,7 @@
import com.vladmihalcea.hibernate.masterclass.laboratory.util.AbstractPostgreSQLIntegrationTest;
import org.junit.Test;

import java.sql.PreparedStatement;
import java.sql.Statement;

import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -40,8 +41,34 @@ public void testStatement() {

int[] updateCounts = statement.executeBatch();

assertEquals(4, updateCounts.length);
assertEquals(3, updateCounts.length);
}
});
}

@Test
public void testPreparedStatement() {
LOGGER.info("Test Statement batch insert");
doInConnection(connection -> {
PreparedStatement postStatement = connection.prepareStatement(
"insert into Post (title, version, id) " +
"values (?, ?, ?)");

postStatement.setString(1, String.format("Post no. %1$d", 1));
postStatement.setInt(2, 0);
postStatement.setLong(3, 1);
postStatement.addBatch();

postStatement.setString(1, String.format("Post no. %1$d", 2));
postStatement.setInt(2, 0);
postStatement.setLong(3, 2);
postStatement.addBatch();

int[] updateCounts = postStatement.executeBatch();

assertEquals(2, updateCounts.length);

postStatement.close();
});
}
}

0 comments on commit a3c1e3a

Please sign in to comment.