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 GuessAB {
- public static void main(String args[]) {
- new MVC_AB() ;
- }
- }
- class MVC_AB implements ActionListener {
- JFrame f;
- Container c;
- JTextField txt;
- JButton btn;
- JPasswordField pss;
- MVC_AB() {
- f=new JFrame("GuessAB");
- f.setLayout(new FlowLayout());
- f.setSize(400,300);
- f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- c=f.getContentPane();
- txt=new JTextField(20);
- c.add(txt);
- pss=new JPasswordField(20);
- c.add(pss);
- btn=new JButton("Submit");
- c.add(btn);
- btn.addActionListener(this);
- f.setVisible(true);
- }
- public void actionPerformed(ActionEvent e) {
- String str=txt.getText();
- try {
- Class.forName("com.mysql.jdbc.Driver");
- } catch (ClassNotFoundException e1) {
- };
- 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");
- Boolean found=false;
- while (rs.next()) {
- System.out.println(rs.getString("user")+""+txt.getText()+""+rs.getString("pswd")+""+pss.getText());
- if((rs.getString("user").equals(txt.getText()))&&(rs.getString("pswd").equals(pss.getText()))) {
- found=true;
- break;
- };
- };
- rs.close();
- conn.close();
- if(found) {
- JOptionPane.showMessageDialog(f,"Sucessful!");
- txt.setText("");
- pss.setText("");
- } else {
- JOptionPane.showMessageDialog(f,"Fail!");
- txt.setText("");
- pss.setText("");
- }
- } catch(SQLException e2) {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement