Advertisement
Guest User

Untitled

a guest
Feb 3rd, 2014
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.57 KB | None | 0 0
  1.  
  2.  
  3. package loginsystem;
  4.  
  5. import javax.swing.*;
  6. import java.awt.event.*;
  7. import java.sql.*;
  8.  
  9. public class LoginSystem {
  10.  
  11.     Connection con;
  12.     Statement st;
  13.     ResultSet rs;
  14.    
  15.     JFrame f = new JFrame("INLOGIN");
  16.     JLabel l = new JLabel("Username");
  17.     JLabel l1 = new JLabel("Password");
  18.     JTextField t = new JTextField(10);
  19.     JTextField t1 = new JTextField(10);
  20.     JButton b = new JButton("Login");
  21.    
  22.     public LoginSystem()
  23.     {
  24.    
  25.     connect();
  26.     frame();
  27.        
  28.     }
  29.    
  30.     public void connect(){
  31.        
  32.         try{
  33.            
  34.        
  35.        
  36.         String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
  37.         Class.forName(driver);
  38.        
  39.         String db = "jdbc:odbc:innlogin";
  40.         con = DriverManager.getConnection(db);
  41.         st = con.createStatement();
  42.         }
  43.         catch(Exception ex)
  44.         {
  45.            
  46.         }
  47.     }
  48.    
  49.     public void frame()
  50.     {
  51.      
  52.        f.setSize(600, 400);
  53.        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  54.        f.setVisible(true);
  55.        
  56.        JPanel p = new JPanel();
  57.        
  58.        p.add(l);
  59.        p.add(t);
  60.        p.add(l1);
  61.        p.add(t1);
  62.        p.add(b);
  63.        
  64.        f.add(p);
  65.        
  66.        b.addActionListener(new ActionListener(){
  67.  
  68.            @Override
  69.            public void actionPerformed(ActionEvent e)
  70.            {
  71.              try
  72.              {
  73.                  
  74.              
  75.                String user = t.getText().trim();
  76.                String pass = t1.getText().trim();
  77.                
  78.                String sql = "select user,pass from Table1 where user = '"+user+"'and pass = '"+pass+"'";
  79.                rs = st.executeQuery(sql);
  80.                
  81.                int count = 0;
  82.                while(rs.next())
  83.                {
  84.                    count = count + 1;
  85.                }
  86.                
  87.                if(count == 1)
  88.                {
  89.                    JOptionPane.showMessageDialog(null, "Bruker funnet!");
  90.                }
  91.                else if(count > 1)
  92.                        {
  93.                            JOptionPane.showMessageDialog(null, "duplikerte brukere fĂ„r ikke tilgang!");
  94.                        }
  95.                else
  96.                {
  97.                    JOptionPane.showMessageDialog(null, "Bruker ikke funnet!");
  98.                }
  99.              }
  100.              catch(Exception ex){
  101.                  
  102.              }
  103.            }
  104.            
  105.     }
  106.     }
  107.    
  108.     public static void main(String[] args) {
  109.        
  110.         new LoginSystem();
  111.        
  112.     }
  113.    
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement