Skip to content

SchemaController: User PreparedStatements where possible #205

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

Merged
Merged
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 @@ -13,6 +13,7 @@

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
Expand Down Expand Up @@ -140,17 +141,22 @@ private Connection getConnection() throws SQLException {
}

private boolean schemaExists(Connection connection, String schemaName) throws SQLException {
ResultSet resultSet = connection.createStatement().executeQuery(
format("SELECT schema_name FROM information_schema.schemata WHERE schema_name = \"%1$s\"",
schemaName));
return resultSet.first();
try (PreparedStatement ps =
connection.prepareStatement("SELECT schema_name FROM information_schema.schemata WHERE schema_name = ?")) {
ps.setString(1, schemaName);
try (ResultSet resultSet = ps.executeQuery()) {
return resultSet.first();
}
}
}

private boolean userExists(Connection connection, String userName) throws SQLException {
try (Statement statement = connection.createStatement()) {
ResultSet resultSet = statement.executeQuery(format("SELECT User FROM mysql.user WHERE User='%1$s'",
userName));
return resultSet.first();
try (PreparedStatement ps =
connection.prepareStatement("SELECT User FROM mysql.user WHERE User = ?")) {
ps.setString(1, userName);
try (ResultSet resultSet = ps.executeQuery()) {
return resultSet.first();
}
}
}
}