Fix 2 findbugs SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING warnings in DatabaseConfig.java

Signed-off-by: Rajani Karuturi <rajanikaruturi@gmail.com>

This closes #478
This commit is contained in:
Rafael da Fonseca 2015-06-17 21:43:50 +02:00 committed by Rajani Karuturi
parent 2993291e7c
commit 5d258fa163

View File

@ -1189,10 +1189,12 @@ public class DatabaseConfig {
sb.append(pwStr);
// create an account for the admin user first
insertSql = "INSERT INTO `cloud`.`account` (id, account_name, type, domain_id) VALUES (" + id + ", '" + username + "', '1', '1')";
insertSql = "INSERT INTO `cloud`.`account` (id, account_name, type, domain_id) VALUES (?, ?, '1', '1')";
txn = TransactionLegacy.currentTxn();
try {
PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql);
stmt.setLong(1, id);
stmt.setString(2, username);
stmt.executeUpdate();
} catch (SQLException ex) {
s_logger.error("error creating account", ex);
@ -1258,11 +1260,12 @@ public class DatabaseConfig {
"INSERT INTO `cloud`.`configuration` (instance, component, name, value, description, category) " + "VALUES ('" + instance + "','" + component + "','" + name +
"','" + value + "','" + description + "','" + category + "')";
String selectSql = "SELECT name FROM cloud.configuration WHERE name = '" + name + "'";
String selectSql = "SELECT name FROM cloud.configuration WHERE name = ?";
TransactionLegacy txn = TransactionLegacy.currentTxn();
try {
PreparedStatement stmt = txn.prepareAutoCloseStatement(selectSql);
stmt.setString(1, name);
ResultSet result = stmt.executeQuery();
Boolean hasRow = result.next();
if (!hasRow) {