hello guys, i am new in java
could anyone help me with it? thanks before
here is my 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); }