could anybody fix my problem? resultset is closed
hello guys, i am new in java
could anyone help me with it? thanks before
here is my code:
Code :
String password = txPass.getText();
String username = txUsername.getText();
//int username1 = Integer.parseInt(username);
//Double username1 = Double.parseDouble(username);
try
{
String dbname="jdbc:odbc:Database";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection(dbname,"admin","admin");
Statement s = con.createStatement();
String sql = "SELECT * FROM admin where Username ='"+username+"' AND Password = '"+password+"' " ;
ResultSet rs = s.executeQuery(sql);
if (rs.next())
{
//throw new Exception();
JOptionPane.showMessageDialog(null, "Login Sukses", "INFO", JOptionPane.INFORMATION_MESSAGE);
Menu_admin admin = new Menu_admin();
admin.setVisible(true);
admin.setUser(rs.getString(1));
dispose();
//setVisible(false);
//new Menu_admin().setVisible(true);
rs.getStatement().close();
}
else
{
try
{
//Statement s = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String skl = "SELECT* FROM mahasiswa where NIM ='"+username+"' AND password = '"+password+"' " ;
ResultSet rk = s.executeQuery(skl);
if (rk.next())
{
JOptionPane.showMessageDialog(null, "Login Sukses", "INFO", JOptionPane.INFORMATION_MESSAGE);
Menu_mhs mhs = new Menu_mhs();
mhs.setVisible(true);
mhs.setMhs(rs.getString(1));
dispose();
//new Menu_dsn().setVisible(true);
}
else
{
try
{
Statement b = con.createStatement();
String sjl = "SELECT* FROM dosen where NID ='"+username+"' AND password = '"+password+"' " ;
ResultSet rj = b.executeQuery(sjl);
if (rj.next())
{
JOptionPane.showMessageDialog(null, "Login Sukses", "INFO", JOptionPane.INFORMATION_MESSAGE);
Menu_dsn dsn = new Menu_dsn();
dsn.setVisible(true);
dsn.setUser(rs.getString(1));
dispose();
//new Menu_mhs().setVisible(true);
}
else
{
JOptionPane.showMessageDialog(null, "Username atau Password salah", "ERROR", JOptionPane.ERROR_MESSAGE);
}
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null,"Error:\n" +e,"ERROR",JOptionPane.WARNING_MESSAGE);
}
}
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null,"Error:\n" +e,"ERROR",JOptionPane.WARNING_MESSAGE);
}
}
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null,"Error:\n" +e,"ERROR",JOptionPane.WARNING_MESSAGE);
// new Menu().setVisible(true);
}
Re: could anybody fix my problem? resultset is closed
You should always call the printStackTrace() method in the catch blocks to get the full text of the error messages so you can see exactly what and where the exception is.
Re: could anybody fix my problem? resultset is closed
Quote:
Originally Posted by
Norm
You should always call the printStackTrace() method in the catch blocks to get the full text of the error messages so you can see exactly what and where the exception is.
OK.. thanks Norm for ur help
my problem is solved right now ;))
the problem came in this line ya
Code :
if (rk.next())
{
JOptionPane.showMessageDialog(null, "Login Sukses", "INFO", JOptionPane.INFORMATION_MESSAGE);
Menu_mhs mhs = new Menu_mhs();
mhs.setMhs(rs.getString(1)); //i just forgot change rs to rk
mhs.setVisible(true);
dispose();
//new Menu_dsn().setVisible(true);
}
just because of that i had wasting time for 5 hours 8-| 8-|
haha. .