Error: http://pastebin.com/G6zZhNMi Code: public void playerProfileExists(Player player) throws SQLException { final String queryCheck = "SELECT * FROM `playerdata` WHERE player = ?"; final PreparedStatement ps = c.prepareStatement(queryCheck); ps.setString(1, player.getName()); final ResultSet resultSet = ps.executeQuery(); final String name = resultSet.getString("player"); if(name == null){ System.out.println("Player doesn't exist"); }else{ System.out.println("Player exists!"); } }
From looking at the stacktrace, I'd assume the issue is caused by you trying to get a string from an empty result set. Code:java final String name = resultSet.getString("player"); Check to see if there's anything in the result set before doing any operations on it. Code:java ResultSet resultSet = ...;int count = 0;while (resultSet.next()) { count++; // Do stuff (put the getString here)} if (count == 0) { // Empty}
Stealth2800 I'm going accordingly through this tutorial: https://forums.bukkit.org/threads/tutorial-using-mysql-in-your-plugins.132309/ So, I can't seem to fathom how they don't provide anything to avoid this error.
Neilnet You're missing a resultSet.next() call after executing the statement, as shown in the tutorial you linked. ResultSet#next also returns a boolean value, false if there are no more rows. You could probably also use that to check if the result set is empty.
Yeah, This did the trick: Code:java public void playerProfileExists(Player player) throws SQLException {final String queryCheck = "SELECT * FROM `playerdata` WHERE player = ?";if(player != null){PreparedStatement ps = c.prepareStatement(queryCheck);ps.setString(1, player.getName());ResultSet resultSet = ps.executeQuery();if(resultSet.next()){String name = resultSet.getString("player");System.out.println("Player " + name + " exists!");}else{System.out.println("Player doesn't exist");}}} Thanks!