package loginsystem;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
public class LoginSystem {
Connection con;
Statement st;
ResultSet rs;
JFrame f = new JFrame("INLOGIN");
JLabel l = new JLabel("Username");
JLabel l1 = new JLabel("Password");
JTextField t = new JTextField(10);
JTextField t1 = new JTextField(10);
JButton b = new JButton("Login");
public LoginSystem()
{
connect();
frame();
}
public void connect(){
try{
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
Class.forName(driver);
String db = "jdbc:odbc:innlogin";
con = DriverManager.getConnection(db);
st = con.createStatement();
}
catch(Exception ex)
{
}
}
public void frame()
{
f.setSize(600, 400);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
JPanel p = new JPanel();
p.add(l);
p.add(t);
p.add(l1);
p.add(t1);
p.add(b);
f.add(p);
b.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e)
{
try
{
String user = t.getText().trim();
String pass = t1.getText().trim();
String sql = "select user,pass from Table1 where user = '"+user+"'and pass = '"+pass+"'";
rs = st.executeQuery(sql);
int count = 0;
while(rs.next())
{
count = count + 1;
}
if(count == 1)
{
JOptionPane.showMessageDialog(null, "Bruker funnet!");
}
else if(count > 1)
{
JOptionPane.showMessageDialog(null, "duplikerte brukere får ikke tilgang!");
}
else
{
JOptionPane.showMessageDialog(null, "Bruker ikke funnet!");
}
}
catch(Exception ex){
}
}
}
}
public static void main(String[] args) {
new LoginSystem();
}
}