Last active
December 20, 2015 02:19
-
-
Save Rockett8855/6055992 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FAStatements { | |
private Main plugin; | |
private Connection conn; | |
public FAStatements(Main plugin) { | |
this.plugin = plugin; | |
this.plugin = this.plugin.getConnection(); | |
} | |
//with a player | |
public void update(String tableName, String columnName, int value, Player player) throws SQLException{ | |
update(tableName, columnName, value, player.getName()); | |
} | |
//with a player | |
public void update(String tableName, String columnName, String value, Player player) throws SQLException{ | |
update(tableName, columnName, value, player.getName()); | |
} | |
//update a column. | |
public void update(String tableName, String columnName, int value, String playerName) throws SQLException { | |
Statement statement = conn.createStatement(); | |
statement.execute("UPDATE " + tableName + " SET " + columnName + "=" + value + " WHERE Name='" + playerName + "';"); | |
statement.close(); | |
} | |
//update a column | |
public void update(String tableName, String columnName, String value, String playerName) throws SQLException { | |
Statement statement = conn.createStatement(); | |
statement.executeUpdate("UPDATE " + tableName + " SET " + columnName + "='" + value + "' WHERE Name='" + playerName + "';"); | |
statement.close(); | |
} | |
//Calls the below function with a player's name. | |
public int getInt(String tableName, String columnName, Archer archer) throws SQLException { | |
return getInt(tableName, columnName, archer.getName()); | |
} | |
//Calls the below function with a player's name. | |
public String getString(String tableName, String columnName, Archer archer) throws SQLException { | |
return getString(tableName, columnName, archer.getName()); | |
} | |
//get Int | |
public int getInt(String tableName, String columnName, String playerName) throws SQLException { | |
Statement statement = conn.createStatement(); | |
ResultSet set = statement.executeQuery("SELECT " + columnName + " FROM " + tableName + " WHERE Name='" + playerName + "';"); | |
if(!set.first()) { | |
//column doesn't exist | |
} | |
int numb = set.getInt(1); | |
set.close(); | |
return numb; | |
} | |
//get String | |
public String getString(String tableName, String columnName, String playerName) throws SQLException { | |
Statement statement = conn.createStatement(); | |
ResultSet set = statement.executeQuery("SELECT " + columnName + " FROM " + tableName + " WHERE Name='" + playerName + "';"); | |
if(set.getMetaData().getColumnCount() == 0) { | |
//Column doesn't exist | |
} | |
String string = set.getString(1); | |
set.close(); | |
return string; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment