fight again npe

This commit is contained in:
Chris 2017-02-13 23:49:41 +01:00
parent e539d344b9
commit 13da8be2af
1 changed files with 42 additions and 33 deletions

View File

@ -43,7 +43,7 @@ public class SQLLite implements IDB
try
{
m_connection = DriverManager.getConnection("jdbc:sqlite:Plugins/PlaytimeReloaded/playtime.db");
m_connection = DriverManager.getConnection("jdbc:sqlite:" + m_plugin.getDataFolder().getAbsolutePath() + "playtime.db");
Statement _statement = m_connection.createStatement();
@ -58,12 +58,15 @@ public class SQLLite implements IDB
public void update(UUID _playerUUID, int _newTime)
{
try
{
if(m_connection != null)
{
Statement _statement = m_connection.createStatement();
_statement.executeUpdate("DELETE FROM playtime WHERE playeruuid = '" + _playerUUID.toString() + "'");
_statement.executeUpdate("INSERT INTO playtime (`playeruuid`, `playtime`) VALUES ('" + _playerUUID.toString() + "', '" + _newTime + "')");
_statement.close();
}
}catch (SQLException _ex) {
_ex.printStackTrace();
}
@ -74,6 +77,8 @@ public class SQLLite implements IDB
List<String[]> _returnList = new ArrayList<String[]>();
try
{
if(m_connection != null)
{
Statement _statement = m_connection.createStatement();
ResultSet _results = _statement.executeQuery("SELECT * FROM playtime ORDER BY playtime DESC LIMIT 5");
@ -91,6 +96,7 @@ public class SQLLite implements IDB
_results.close();
_statement.close();
}
}catch (SQLException _ex) {
_ex.printStackTrace();
}
@ -101,6 +107,8 @@ public class SQLLite implements IDB
public int getPlayerTime(UUID _playerUUID)
{
try
{
if(m_connection != null)
{
Statement _statement = m_connection.createStatement();
ResultSet _results = _statement.executeQuery("SELECT * FROM playtime WHERE `playeruuid` = '" + _playerUUID.toString() + "'");
@ -118,6 +126,7 @@ public class SQLLite implements IDB
_results.close();
_statement.close();
}
}catch (SQLException _ex) {
_ex.printStackTrace();
}