Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public PreparedStatementImpl(ConnectionImpl connection, String sql) throws SQLEx
this.parameterMetaData = new ParameterMetaDataImpl(this.parameters.length);
}

private String compileSql(String [] segments) {
private String compileSql(String []segments) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < segments.length; i++) {
sb.append(segments[i]);
Expand Down Expand Up @@ -217,7 +217,7 @@ public void setBinaryStream(int parameterIndex, InputStream x, int length) throw
public void clearParameters() throws SQLException {
checkClosed();
if (originalSql.contains("?")) {
this.parameters = new Object[sqlSegments.length];
this.parameters = new Object[sqlSegments.length - 1];
} else {
this.parameters = new Object[0];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
import java.sql.Types;
import java.util.Arrays;
Expand Down Expand Up @@ -553,4 +552,31 @@ void testStatementSplit() throws Exception {

}
}

@Test(groups = {"integration"})
void testClearParameters() throws Exception {
String sql = "insert into `test_issue_2299` (`id`, `name`, `age`) values (?, ?, ?)";
try (Connection conn = getJdbcConnection();
PreparedStatementImpl ps = (PreparedStatementImpl) conn.prepareStatement(sql)) {

try (Statement stmt = conn.createStatement()) {
stmt.execute("CREATE TABLE IF NOT EXISTS `test_issue_2299` (`id` Nullable(String), `name` Nullable(String), `age` Int32) ENGINE Memory;");
}

Assert.assertEquals(ps.parameters.length, 3);

ps.setString(1, "testId");
ps.setString(2, "testName");
ps.setInt(3, 18);
ps.execute();

ps.clearParameters();
Assert.assertEquals(ps.parameters.length, 3);

ps.setString(1, "testId2");
ps.setString(2, "testName2");
ps.setInt(3, 19);
ps.execute();
}
}
}