Hey, I'm having problems with this code
CODE
private boolean isLogged() {
ResultSet is = null;
try {
is = dtb.query("SELECT * FROM `active_users` WHERE ip = '"+this.IP+"'");
} catch(Exception e) {
System.err.println("Couldn't execute SQL query: "+e);
}
try {
int count = 0;
while(is.next())
count++;
UI.showMsg("Number of records "+count);
is.close();
if(count > 0) {
if(debug)
System.out.println("Logged in");
return true;
}
else {
if(debug)
System.out.println("Logged out");
return false;
}
} catch(Exception e) {
if(debug)
System.err.println("Error checking for row: "+e);
}
return false; //If it got here it means there is an error
}
DB.java
CODE
/*
* DB.java
*
* Created on 10 June 2007, 01:38
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package icadmin.MySql;
import java.sql.*;
import icadmin.UI;
/**
*
*/
public class DB {
Connection con = null;
/** Creates a new instance of DB */
public DB(String serv, String db, String user, String pass) {
String url = "jdbc:mysql://"+serv+"/"+db+"?user="+user+"&password="+pass;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection(url);
} catch (Exception e) {
UI.showErr("Error: "+e);
}
}
public ResultSet query(String que) {
if(con == null) return null;
Statement st = null;
ResultSet rs = null;
try {
st = con.createStatement();
rs = st.executeQuery(que);
} catch (SQLException e) {
System.err.println("Culdn't execute SQL command: "+e);
return null;
} finally {
try {
st.close();
} catch(SQLException e) {}
}
que = null;
return rs;
}
public boolean close() {
try {
if(con != null)
con.close();
} catch(SQLException e) {
return false;
}
return true;
}
}
function isLogged() never returns true even if there are entries in thre database.