diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index 445ffde1e538..315fa8c9cb21 100644 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -926,7 +926,7 @@ protected void checkIfPodIsDeletable(final long podId) { dbName = "cloud"; } - String selectSql = "SELECT * FROM `" + dbName + "`.`" + tableName + "` WHERE " + column + " = ?"; + String selectSql = "SELECT * FROM `?`.`?` WHERE ? = ?"; if(tableName.equals("vm_instance")) { selectSql += " AND state != '" + VirtualMachine.State.Expunging.toString() + "' AND removed IS NULL"; @@ -939,7 +939,10 @@ protected void checkIfPodIsDeletable(final long podId) { final TransactionLegacy txn = TransactionLegacy.currentTxn(); try { final PreparedStatement stmt = txn.prepareAutoCloseStatement(selectSql); - stmt.setLong(1, podId); + stmt.setString(1,dbName); + stmt.setString(2,tableName); + stmt.setString(3,column); + stmt.setLong(4, podId); final ResultSet rs = stmt.executeQuery(); if (rs != null && rs.next()) { throw new CloudRuntimeException("The pod cannot be deleted because " + errorMsg); @@ -1385,7 +1388,7 @@ protected void checkIfZoneIsDeletable(final long zoneId) { final String dbName = "cloud"; - String selectSql = "SELECT * FROM `" + dbName + "`.`" + tableName + "` WHERE " + column + " = ?"; + String selectSql = "SELECT * FROM `?`.`?` WHERE ? = ?"; if (tableName.equals("op_dc_vnet_alloc")) { selectSql += " AND taken IS NOT NULL"; @@ -1410,7 +1413,10 @@ protected void checkIfZoneIsDeletable(final long zoneId) { final TransactionLegacy txn = TransactionLegacy.currentTxn(); try { final PreparedStatement stmt = txn.prepareAutoCloseStatement(selectSql); - stmt.setLong(1, zoneId); + stmt.setString(1,dbName); + stmt.setString(2,tableName); + stmt.setString(3,column); + stmt.setLong(4, zoneId); final ResultSet rs = stmt.executeQuery(); if (rs != null && rs.next()) { throw new CloudRuntimeException("The zone is not deletable because " + errorMsg);