Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
|CONJ-264] SQLException when calling PreparedStatement.executeBatch()…
… without calling addBatch().
  • Loading branch information
rusher committed Mar 7, 2016
1 parent db08fc1 commit 6634fa5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Expand Up @@ -204,8 +204,8 @@ public ResultSetMetaData getMetaData() throws SQLException {
public int[] executeBatch() throws SQLException {
checkClose();
batchResultSet = null;
if (parameterCount > 0 && queryParameters.size() == 0) {
throw ExceptionMapper.getSqlException("No Parameters set. The command addBatch() must have been set");
if (queryParameters.size() == 0) {
return new int[0];
}
int counter = 0;
int[] ret = new int[queryParameters.size()];
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/org/mariadb/jdbc/PreparedStatementTest.java
Expand Up @@ -135,4 +135,20 @@ public void testPreparedStatementsWithQuotes() throws SQLException {
assertEquals(true, rs.getBoolean(4));
}

/**
* CONJ-264: SQLException when calling PreparedStatement.executeBatch() without calling addBatch().
*
* @throws SQLException exception
*/
@Test
public void testExecuteBatch() throws SQLException {
PreparedStatement preparedStatement = sharedConnection.prepareStatement("INSERT INTO table1 VALUE ?");
try {
int[] result = preparedStatement.executeBatch();
assertEquals(0, result.length);
} catch (SQLException sqle) {
fail("Must not throw error");
}

}
}

0 comments on commit 6634fa5

Please sign in to comment.