Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: executeUpdate bug #110

Merged
merged 1 commit into from
Dec 7, 2023
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 @@ -363,23 +363,33 @@ private List<StatementInfoWrapper> prepareSQL(@NonNull Map<Integer, String> para
@Override
public boolean execute()
throws SQLException {
return this.execute(prepareSQL(batchInsertUtils.get().getProvideParams())).isPresent();
Boolean r;
try {
r = this.execute(prepareSQL(batchInsertUtils.get().getProvideParams())).isPresent();
} catch (Exception e) {
throw new SQLException(e);
} finally {
clearBatch();
}
return r;
}

protected Optional<ResultSet> execute(List<StatementInfoWrapper> statements) throws SQLException {
Optional<ResultSet> resultSet = Optional.empty();
Optional<ResultSet> optionalResultSet = Optional.empty();
ResultSet r;
try {
for (int i = 0; i < statements.size(); i++) {
if (i == 0) {
internalExecute(statements.get(i).getSql(), null);
resultSet = Optional.ofNullable(getResultSet());
} else {
internalExecute(statements.get(i).getSql(), null);
internalExecute(statements.get(i).getSql(), null);
r = getResultSet();
optionalResultSet = Optional.ofNullable(r);
while (r != null && r.next()) {
}
}
} catch (Exception e) {
throw new SQLException(e);
} finally {
}
return resultSet;
return optionalResultSet;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
Expand Down Expand Up @@ -297,6 +297,15 @@ public void testPrepareStatementExecute() throws SQLException {
Assertions.assertEquals(1, r.getLong("number"));
System.out.println(r.getLong("number"));
}
try {
Statement statement = conn.createStatement();
ResultSet rs = statement.executeQuery("show processlist");
while (rs.next()) {
System.out.println(rs.getString("id"));
}
} catch (Exception e) {
e.printStackTrace();
}
}

@Test
Expand Down Expand Up @@ -339,7 +348,7 @@ public void testAllPreparedStatement() throws SQLException {
String deleteSQL = "delete from test_prepare_statement where a = ?";
try (PreparedStatement statement = conn.prepareStatement(deleteSQL)) {
statement.setInt(1, 1);
int result = statement.executeUpdate();
boolean result = statement.execute();
System.out.println(result);
}
ResultSet r3 = conn.createStatement().executeQuery("select * from test_prepare_statement");
Expand Down
Loading