Skip to content

Commit

Permalink
(#314) Fix NPE on clearParameters (#315)
Browse files Browse the repository at this point in the history
  • Loading branch information
pan3793 authored Mar 1, 2021
1 parent e87c8ec commit 79083a8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ public ResultSetMetaData getMetaData() throws SQLException {

@Override
public void clearParameters() throws SQLException {
Arrays.fill(parameters, null);
if (parameters != null) {
Arrays.fill(parameters, null);
}
}

protected String assembleQueryPartsAndParameters() throws SQLException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package com.github.housepower.jdbc;

import com.github.housepower.jdbc.annotation.Issue;
import com.github.housepower.jdbc.misc.DateTimeUtil;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -234,4 +235,22 @@ public void successfullyInsertData() throws Exception {
});
}

@Test
@Issue(channel = "GitHub", value = "314", link = "https://github.com/housepower/ClickHouse-Native-JDBC/issues/314")
public void ghIssue314() throws Exception {
withNewConnection(connection -> {
Statement statement = connection.createStatement();

statement.execute("DROP TABLE IF EXISTS test");
statement.execute("CREATE TABLE test(id UInt8)ENGINE = Log");

PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO test VALUES(?)");
preparedStatement.clearParameters();
preparedStatement.setByte(1, (byte) 1);
preparedStatement.clearParameters();
preparedStatement.setByte(1, (byte) 1);
assertEquals(1, preparedStatement.executeUpdate());
});
}

}

0 comments on commit 79083a8

Please sign in to comment.