HELP!? SQLException: Invalid handle
Hi friends,
I am facing a problem in my program with ODBC-SQL Server 2000.
The program originally ran smooth with one SELECT statement. But I modified the class and added a method with a new SELECT statement, the error appears.
The old SELECT statement works but the new one gives the error. What should I do to give more than one SELECT statements in a class?
Thank a lot.
Diffserv
PS: My code, (Error occurs in the method getUserInfo)
import java.sql.*;
/* Handle the Login Data */
public class LoginCtlClass
{
final static String myDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
static Connection con = null;
String dSN;
String dataSource;
String dataLogin;
String dataPassword;
String infoTable;
String usernameField;
String passwordField;
Statement thzStatement;
ResultSet thzRS;
LoginCtlClass(String myDSN, String myDataLogin, String myDataPassword, String myInfoTable, String myUsernameField, String myPasswordField)
{
dSN = myDSN;
dataSource = "jdbc:odbc:" + dSN;
dataLogin = myDataLogin;
dataPassword = myDataPassword;
infoTable = myInfoTable;
usernameField = myUsernameField;
passwordField = myPasswordField;
}
public int open()
{
try
{
Class.forName(myDriver);
con = DriverManager.getConnection(dataSource, dataLogin, dataPassword);
thzStatement = con.createStatement();
}
catch(java.lang.ClassNotFoundException e)
{
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
return -1;
}
catch(Exception e)
{
System.err.println(e.getMessage());
return -2;
}
return 0;
}
public void close()
{
try
{
thzStatement.close();
con.close();
}
catch(Exception e)
{
System.err.println("LoginCtlClass Close Error: " + e);
}
}
public boolean pass(String myUsername, String myPassword)
{
String thzSQL;
int noOfUser = 0;
try
{
thzSQL = "SELECT count(*) as noOfUser FROM " + infoTable + " WHERE " + usernameField + "='" + myUsername + "' AND " + passwordField + "='" + myPassword + "'";
thzRS = thzStatement.executeQuery(thzSQL);
if (thzRS.next())
{
noOfUser = thzRS.getInt("noOfUser");
}
thzRS.close();
}
catch(SQLException ex)
{
System.err.println("SQLException in pass(): " + ex.getMessage());
return false;
}
catch(Exception e)
{
System.err.println("LoginCtlClas Error: " + e);
return false;
}
if (noOfUser <= 0)
{
return false;
}
else
{
return true;
}
}
public String getUserInfo(String myUsername, String myPassword, String myInfoField)
{
String thzSQL;
String sqlResult = "";
try
{
thzSQL = "SELECT " + myInfoField + " as SQLresult FROM " + infoTable + " WHERE " + usernameField + "='" + myUsername + "' AND " + passwordField + "='" + myPassword + "'";
thzRS = thzStatement.executeQuery(thzSQL);
System.err.println(thzSQL);
if (thzRS.next())
{
sqlResult = thzRS.getString("SQLresult");
}
thzRS.close();
}
catch(SQLException ex)
{
System.err.println("SQLException in getUserInfo: " + ex.getMessage() + " / " + ex.toString());
return "<ERROR>";
}
catch(Exception e)
{
System.err.println("LoginCtlClas Error: " + e);
return "<ERROR>";
}
return sqlResult;
}
}

