Skip to content

Commit

Permalink
fix ExecuteUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
hantmac committed Nov 16, 2023
1 parent a42df62 commit 582a03b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,9 @@ protected Optional<ResultSet> execute(List<StatementInfoWrapper> statements) thr
}

@Override
public int executeUpdate()
throws SQLException {
return 0;
public int executeUpdate() throws SQLException {
this.execute(prepareSQL(batchInsertUtils.get().getProvideParams())).isPresent();
return batchInsertUtils.get().getProvideParams().size();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;

public class TestPrepareStatement {
private Connection createConnection()
Expand Down Expand Up @@ -88,8 +89,8 @@ public void TestConvertSQLWithBatchValues() throws SQLException {

List<String[]> batchValues1 = new ArrayList<>();
// Add string arrays to batchValues
String[] values3 = {"1","2"};
String[] values4 = {"3","4"};
String[] values3 = {"1", "2"};
String[] values4 = {"3", "4"};
batchValues1.add(values3);
batchValues1.add(values4);

Expand Down Expand Up @@ -288,7 +289,7 @@ public void TestBatchReplaceInto() throws SQLException {
public void testPrepareStatementExecute() throws SQLException {
Connection conn = createConnection();
String sql = "SELECT number from numbers(100) where number = ?";
try(PreparedStatement statement = conn.prepareStatement(sql)) {
try (PreparedStatement statement = conn.prepareStatement(sql)) {
statement.setInt(1, 1);
statement.execute();
ResultSet r = statement.getResultSet();
Expand All @@ -297,4 +298,16 @@ public void testPrepareStatementExecute() throws SQLException {
System.out.println(r.getLong("number"));
}
}

@Test
public void testPrepareStatementExecuteUpdate() throws SQLException {
String sql = "insert into test_prepare_statement values (?,?)";
Connection conn = createConnection();
try (PreparedStatement statement = conn.prepareStatement(sql)) {
statement.setInt(1, 1);
statement.setInt(2, 2);
int result = statement.executeUpdate();
Assertions.assertEquals(2, result);
}
}
}

0 comments on commit 582a03b

Please sign in to comment.