Hey,
I am adding grand exchange to my server and everything works fine except one method:
Code:
public static void getCollect(final Client c, final String Username){
try {
String query = "SELECT * FROM collections";
ResultSet rs = query(query);
while(rs.next()){
int id = Integer.parseInt(rs.getString("itemid"));
int amt = Integer.parseInt(rs.getString("amount"));
String name = rs.getString("username");
if(name.equalsIgnoreCase(Username)){
c.getItems().addItem(id, amt);
c.sendMessage("Successfully collected GE Items.");
query("DELETE FROM `collections` WHERE username = '"+ Username + "' AND `itemid` = '"+id+"' AND `amount` = '"+amt+"'");
}else{
c.sendMessage("@dre@You have nothing to collect!");
}
}
} catch (Exception e) {
e.printStackTrace();
con = null;
stm = null;
}
}
Whenever I type ::collectge (it calls the getCollect Method) I get a null pointer. Can some one please tell me what I am doing wrong. (This is my first time using JDBC).
Error:
Code:
[12/3/11 12:20 PM]: java.lang.NullPointerException
[12/3/11 12:20 PM]: at server.model.players.GrandExchange.getCollect(GrandEx
change.java:612)
P.S Line 612 is: Resultset rs = query(query)
EDIT: MY QUERY METHOD:
Code:
public static ResultSet query(String s) throws SQLException {
try {
if (s.toLowerCase().startsWith("select")) {
ResultSet rs = stm.executeQuery(s);
return rs;
} else {
stm.executeUpdate(s);
}
return null;
} catch (Exception e) {
e.printStackTrace();
con = null;
stm = null;
}
return null;
}
Thanks,
Saad