|
13 | 13 |
|
14 | 14 | import java.sql.Connection; |
15 | 15 | import java.sql.DriverManager; |
| 16 | +import java.sql.PreparedStatement; |
16 | 17 | import java.sql.ResultSet; |
17 | 18 | import java.sql.SQLException; |
18 | 19 | import java.sql.Statement; |
@@ -140,17 +141,22 @@ private Connection getConnection() throws SQLException { |
140 | 141 | } |
141 | 142 |
|
142 | 143 | private boolean schemaExists(Connection connection, String schemaName) throws SQLException { |
143 | | - ResultSet resultSet = connection.createStatement().executeQuery( |
144 | | - format("SELECT schema_name FROM information_schema.schemata WHERE schema_name = \"%1$s\"", |
145 | | - schemaName)); |
146 | | - return resultSet.first(); |
| 144 | + try (PreparedStatement ps = |
| 145 | + connection.prepareStatement("SELECT schema_name FROM information_schema.schemata WHERE schema_name = ?")) { |
| 146 | + ps.setString(1, schemaName); |
| 147 | + try (ResultSet resultSet = ps.executeQuery()) { |
| 148 | + return resultSet.first(); |
| 149 | + } |
| 150 | + } |
147 | 151 | } |
148 | 152 |
|
149 | 153 | private boolean userExists(Connection connection, String userName) throws SQLException { |
150 | | - try (Statement statement = connection.createStatement()) { |
151 | | - ResultSet resultSet = statement.executeQuery(format("SELECT User FROM mysql.user WHERE User='%1$s'", |
152 | | - userName)); |
153 | | - return resultSet.first(); |
| 154 | + try (PreparedStatement ps = |
| 155 | + connection.prepareStatement("SELECT User FROM mysql.user WHERE User = ?")) { |
| 156 | + ps.setString(1, userName); |
| 157 | + try (ResultSet resultSet = ps.executeQuery()) { |
| 158 | + return resultSet.first(); |
| 159 | + } |
154 | 160 | } |
155 | 161 | } |
156 | 162 | } |
0 commit comments