diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/DatabendPreparedStatement.java b/databend-jdbc/src/main/java/com/databend/jdbc/DatabendPreparedStatement.java index 4af2c46a..ed0dfb2f 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/DatabendPreparedStatement.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/DatabendPreparedStatement.java @@ -383,9 +383,9 @@ protected Optional execute(List 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 diff --git a/databend-jdbc/src/test/java/com/databend/jdbc/TestPrepareStatement.java b/databend-jdbc/src/test/java/com/databend/jdbc/TestPrepareStatement.java index c0454969..b420fc96 100644 --- a/databend-jdbc/src/test/java/com/databend/jdbc/TestPrepareStatement.java +++ b/databend-jdbc/src/test/java/com/databend/jdbc/TestPrepareStatement.java @@ -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() @@ -88,8 +89,8 @@ public void TestConvertSQLWithBatchValues() throws SQLException { List 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); @@ -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(); @@ -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); + } + } }