Code:
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;
public class login extends JFrame
{
private JPanel jPanel12;
private JLabel statusMsgLB;
private JLabel statusLB;
private JButton abbr;
private JButton ok;
private JLabel login;
private JPasswordField passein;
private JComboBox statusein;
private JTextField nameein;
private JLabel account;
private JLabel passwort;
private JLabel name;
private JPanel eingabe;
private AdminZugriff adminPanel;
private LehrerZugriff lehrerPanel;
private SchülerZugriff schülerPanel;
static Connection con;
static Statement sqlAnweisung;
static ResultSet result;
static String sqlzeile;
static String nameeinErgebnis;
static String passwortErgebnis;
static String sqlname;
static String sqlpasswort;
public login()
{
super();
try
{
javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel");
}
catch(Exception e)
{
e.printStackTrace();
}
//setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
setLayout(null);
login = new JLabel();
statusMsgLB = new JLabel();
name = new JLabel();
nameein = new JTextField();
passwort = new JLabel();
passein = new JPasswordField();
account = new JLabel();
statusein = new JComboBox();
ok = new JButton();
abbr = new JButton();
statusLB = new JLabel();
add(nameein);
add(name);
add(passein);
add(statusein);
add(statusMsgLB);
add(account);
add(passwort);
add(login);
add(ok);
add(statusLB);
add(abbr);
nameein.setBounds(20,20,100,30);
name.setBounds(120,20,100,30);
passein.setBounds(20,60,100,30);
statusein.setBounds(120,60,100,30);
statusMsgLB.setBounds(20,90,100,30);
account.setBounds(20,120,100,30);
passwort.setBounds(20,150,100,30);
login.setBounds(20,180,100,30);
ok.setBounds(20,210,100,30);
statusLB.setBounds(240,20,100,30);
abbr.setBounds(270,20,100,30);
passwort.setText("Passwort:");
account.setText("Account:");
passwort.setText("Passwort:");
name.setText("Name:");
statusMsgLB.setText("Alles OK");
login.setText("Bitte Loggen Sie sich ein:");
abbr.setText("Abbrechen");
statusLB.setText("Status:");
ok.setText("OK");
statusein.addItem("Schüler");
statusein.addItem("Lehrer");
statusein.addItem("Admin");
ok.addActionListener(new ButLog());
abbr.addActionListener(new ButLog());
try
{
connectDB();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void connectDB() throws ClassNotFoundException, SQLException
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:login","","");
}
public void passPruefen ()
{
}
class ButLog implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String pass,name;
if (e.getSource().equals(ok))
{
nameeinErgebnis = nameein.getText();
passwortErgebnis = passein.getText();
//passwortErgebnis = (passein.getPassword()).toString();
//---------------------------------- Schüler Account Abrage ---------------------------------------//
if (statusein.getSelectedItem().toString().equals("Schüler"))
{
try
{
sqlname = "Select * from LoginSchueler where Name = '"+nameeinErgebnis+"'";
sqlAnweisung=con.createStatement();
result = sqlAnweisung.executeQuery(sqlname);
result.next();
name = result.getString("Name");
pass = result.getString("Passwort");
result.close();
if (nameeinErgebnis.equals(name) && passwortErgebnis.equals(pass))
{
schülerPanel = new SchülerZugriff();
}
else
{
statusMsgLB.setText("Password/User existiert nicht");
}
}
catch (SQLException a)
{
a.printStackTrace();
}
}
//------------------------------------- Lehrer Account Abfrage ------------------------------------//
if (statusein.getSelectedItem().toString().equals("Lehrer"));
{
try
{
sqlname = "Select * from LoginLehrer where Name = '"+nameeinErgebnis+"'";
sqlAnweisung=con.createStatement();
result = sqlAnweisung.executeQuery(sqlname);
result.next();
name = result.getString("Name");
pass = result.getString("Passwort");
result.close();
if (nameeinErgebnis.equals(name) && passwortErgebnis.equals(pass))
{
lehrerPanel = new LehrerZugriff();
}
else
{
statusMsgLB.setText("Password/User existiert nicht");
}
}
catch (SQLException a)
{
a.printStackTrace();
}
}
//------------------------------------- Admin Account Abfrage -------------------------------------//
if (statusein.getSelectedItem().toString().equals("Admin"));
{
try
{
sqlname = "Select * from LoginAdmin where Name = '"+nameeinErgebnis+"'";
sqlAnweisung=con.createStatement();
result = sqlAnweisung.executeQuery(sqlname);
result.next();
name = result.getString("Name");
pass = result.getString("Passwort");
result.close();
if (nameeinErgebnis.equals(name) && passwortErgebnis.equals(pass))
{
adminPanel = new AdminZugriff();
}
else
{
statusMsgLB.setText("Password/User existiert nicht");
}
}
catch (SQLException a)
{
a.printStackTrace();
}
}
//--------------------------------------- Login Abbrechen ---------------------------------------//
if (e.getSource().equals(abbr))
{
try
{
System.exit(0);
}
catch (Exception a)
{
a.printStackTrace();
}
}
//---------------------------------- Ende Login Abbrechen ---------------------------------------//
}
}
}
public static void main(String[] args) //throws ClassNotFoundException, SQLException
{
login inst = new login();
inst.setSize(600,400);
inst.setLocation(300,200);
inst.setVisible(true);
}
}
Fehlermeldung:
Code:
[Microsoft][ODBC Driver Manager] Ungültiger Cursorstatus
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLGetDataString(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcResultSet.getDataString(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcResultSet.getString(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcResultSet.getString(Unknown Source)
at login$ButLog.actionPerformed(login.java:185)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Ungültiger Cursorstatus
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLGetDataString(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcResultSet.getDataString(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcResultSet.getString(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcResultSet.getString(Unknown Source)
at login$ButLog.actionPerformed(login.java:214)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Warum ungültiger Cursorstatus?