mirror of
https://github.com/Zrips/Jobs.git
synced 2024-11-26 12:35:28 +01:00
Do not create unnecessary statement when checking table
This commit is contained in:
parent
ba601dde43
commit
77295b6041
@ -77,16 +77,10 @@ public class JobsMySQL extends JobsDAO {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isTable(String table) {
|
public boolean isTable(String table) {
|
||||||
Statement statement;
|
|
||||||
JobsConnection conn = getConnection();
|
JobsConnection conn = getConnection();
|
||||||
if (conn == null)
|
if (conn == null)
|
||||||
return false;
|
return false;
|
||||||
try {
|
|
||||||
statement = conn.createStatement();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
Jobs.consoleMsg("&cCould not check if its table, SQLException: " + e.getMessage());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
ResultSet tables = conn.getMetaData().getTables(null, null, table, null);
|
ResultSet tables = conn.getMetaData().getTables(null, null, table, null);
|
||||||
if (tables.next()) {
|
if (tables.next()) {
|
||||||
@ -97,8 +91,8 @@ public class JobsMySQL extends JobsDAO {
|
|||||||
return false;
|
return false;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
Jobs.consoleMsg("Not a table |" + "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME ='" + table + "';" + "|");
|
Jobs.consoleMsg("Not a table |" + "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME ='" + table + "';" + "|");
|
||||||
close(statement);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PreparedStatement insert = null;
|
PreparedStatement insert = null;
|
||||||
ResultSet res = null;
|
ResultSet res = null;
|
||||||
try {
|
try {
|
||||||
@ -107,16 +101,15 @@ public class JobsMySQL extends JobsDAO {
|
|||||||
if (res.next()) {
|
if (res.next()) {
|
||||||
close(res);
|
close(res);
|
||||||
close(insert);
|
close(insert);
|
||||||
close(statement);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
Jobs.consoleMsg("Not a table |" + "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME ='" + table + "';" + "|");
|
Jobs.consoleMsg("Not a table |" + "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME ='" + table + "';" + "|");
|
||||||
} finally {
|
} finally {
|
||||||
}
|
|
||||||
close(res);
|
close(res);
|
||||||
close(insert);
|
close(insert);
|
||||||
close(statement);
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,8 +162,7 @@ public class JobsMySQL extends JobsDAO {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
statement = getConnection().createStatement();
|
statement = getConnection().createStatement();
|
||||||
String query = "DELETE FROM " + table + ";";
|
statement.executeUpdate("DELETE FROM " + table + ";");
|
||||||
statement.executeUpdate(query);
|
|
||||||
return true;
|
return true;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
Jobs.consoleMsg("&cCould not wipe table, SQLException: " + e.getMessage());
|
Jobs.consoleMsg("&cCould not wipe table, SQLException: " + e.getMessage());
|
||||||
@ -184,15 +176,13 @@ public class JobsMySQL extends JobsDAO {
|
|||||||
@Override
|
@Override
|
||||||
public boolean drop(String table) {
|
public boolean drop(String table) {
|
||||||
Statement statement = null;
|
Statement statement = null;
|
||||||
String query = null;
|
|
||||||
try {
|
try {
|
||||||
if (!isTable(table)) {
|
if (!isTable(table)) {
|
||||||
Jobs.consoleMsg("&cTable \"" + table + "\" does not exist.");
|
Jobs.consoleMsg("&cTable \"" + table + "\" does not exist.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
statement = getConnection().createStatement();
|
statement = getConnection().createStatement();
|
||||||
query = "DROP TABLE IF EXISTS `" + table + "`;";
|
statement.executeUpdate("DROP TABLE IF EXISTS `" + table + "`;");
|
||||||
statement.executeUpdate(query);
|
|
||||||
return true;
|
return true;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
Jobs.consoleMsg("&cCould not wipe table, SQLException: " + e.getMessage());
|
Jobs.consoleMsg("&cCould not wipe table, SQLException: " + e.getMessage());
|
||||||
|
Loading…
Reference in New Issue
Block a user