Advertisement
Guest User

Untitled

a guest
Apr 20th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.97 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4. import java.util.*;
  5. import java.sql.*;
  6.  
  7. public class Test {
  8.     public static void main(String[] args) {
  9.         new MVC_AB();
  10.     }
  11. }
  12.  
  13. class MVC_AB extends MouseAdapter {
  14.     JFrame f;
  15.     Container c;
  16.     JTextField txt1,txt2;
  17.     JButton btn;
  18.     MVC_AB() {
  19.  
  20.         f=new JFrame("LOGIN");
  21.         f.setLayout(new FlowLayout());
  22.         f.setSize(400,300);
  23.         f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  24.         c=f.getContentPane();
  25.  
  26.         txt1=new JTextField(20);
  27.         c.add(txt1);
  28.  
  29.         txt2=new JTextField(20);
  30.         c.add(txt2);
  31.  
  32.         btn=new JButton("Submit");
  33.         c.add(btn);
  34.         btn.addMouseListener(this);
  35.  
  36.  
  37.         f.setVisible(true);
  38.     }
  39.     public void mouseClicked(MouseEvent E) {
  40.         int found=0;;
  41.         String S,U,P;
  42.         U=txt1.getText();
  43.         P=txt2.getText();
  44.  
  45.         try {
  46.             Class.forName("com.mysql.jdbc.Driver");
  47.         } catch (ClassNotFoundException e) {
  48.         };
  49.  
  50.         try {
  51.             Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3307/db1?user=abc&password=123");
  52.             Statement stmt=conn.createStatement();
  53.             ResultSet rs=stmt.executeQuery("SELECT * FROM tb1");
  54.             while (rs.next()) {
  55.                 String user=rs.getString("user");
  56.                 String pswd=rs.getString("pswd");
  57.                 if(U.equals(rs.getString("user"))&&P.equals(rs.getString("pswd"))) {
  58.                     found=1;
  59.                     break;
  60.                 }
  61.             };
  62.             rs.close();
  63.             conn.close();
  64.         } catch (SQLException e) {
  65.             JOptionPane.showMessageDialog(f,"Fail");
  66.         };
  67.         if(found==1) {
  68.             JOptionPane.showMessageDialog(f,"Sucess");
  69.         } else {
  70.             JOptionPane.showMessageDialog(f,"Fail");
  71.             txt1.setText("");
  72.             txt2.setText("");
  73.         }
  74.  
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement