Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- import java.util.*;
- import java.sql.*;
- public class Test {
- public static void main(String[] args) {
- new MVC_AB();
- }
- }
- class MVC_AB extends MouseAdapter {
- JFrame f;
- Container c;
- JTextField txt1,txt2;
- JButton btn;
- MVC_AB() {
- f=new JFrame("LOGIN");
- f.setLayout(new FlowLayout());
- f.setSize(400,300);
- f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- c=f.getContentPane();
- txt1=new JTextField(20);
- c.add(txt1);
- txt2=new JTextField(20);
- c.add(txt2);
- btn=new JButton("Submit");
- c.add(btn);
- btn.addMouseListener(this);
- f.setVisible(true);
- }
- public void mouseClicked(MouseEvent E) {
- int found=0;;
- String S,U,P;
- U=txt1.getText();
- P=txt2.getText();
- try {
- Class.forName("com.mysql.jdbc.Driver");
- } catch (ClassNotFoundException e) {
- };
- try {
- Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3307/db1?user=abc&password=123");
- Statement stmt=conn.createStatement();
- ResultSet rs=stmt.executeQuery("SELECT * FROM tb1");
- while (rs.next()) {
- String user=rs.getString("user");
- String pswd=rs.getString("pswd");
- if(U.equals(rs.getString("user"))&&P.equals(rs.getString("pswd"))) {
- found=1;
- break;
- }
- };
- rs.close();
- conn.close();
- } catch (SQLException e) {
- JOptionPane.showMessageDialog(f,"Fail");
- };
- if(found==1) {
- JOptionPane.showMessageDialog(f,"Sucess");
- } else {
- JOptionPane.showMessageDialog(f,"Fail");
- txt1.setText("");
- txt2.setText("");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement