0% found this document useful (0 votes)
17 views

Data Base

Uploaded by

Achal Meshram
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Data Base

Uploaded by

Achal Meshram
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

package data;

import java.awt.Font;

import java.sql.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.sql.ResultSet;

import javax.swing.*;

import com.mysql.jdbc.Connection;

import com.mysql.jdbc.Statement;

public class adminlogin extends JFrame implements ActionListener{

JFrame jf;

JTextField t1,t2;

JButton login;

JLabel l1,l2;

public adminlogin() {

jf=new JFrame("Admin Login");

l1=new JLabel("Username");

l1.setBounds(50,100,200,30);

l2=new JLabel("Password");

l2.setBounds(50,200,100,50);

t1=new JTextField();
t1.setBounds(110,100,200,30);

t2=new JTextField();

t2.setBounds(110,200,200,30);

jf.add(l1);

jf.add(l2);

jf.add(t1);

jf.add(t2);

jf.setSize(400,400);

jf.setLayout(null);

jf.setVisible(true);

// JFrame login=new JFrame("Button Example");

login=new JButton("Login");

login.setBounds(150,250,95,30);

login.addActionListener(this);

jf.add(login);

jf.setSize(400,400);

jf.setLayout(null);

jf.setVisible(true);

public void actionPerformed(ActionEvent e)

String userValue=t1.getText();

String passValue=t2.getText();

try( Connection con=(Connection) data.DbConnection.getConnect();

Statement stmt=(Statement) con.createStatement();


ResultSet rs=stmt.executeQuery("select * from admin");

System.out.println(userValue);

System.out.println(passValue);

while(rs.next()) {

System.out.println(rs.getString("password"));

if(rs.getString("username").equals(userValue) &&
rs.getString("password").equals(passValue))

NewPage n=new NewPage();

jf.setVisible(false);

else {

JOptionPane.showMessageDialog(jf, "Username and Password not


matched");

catch(Exception ee)

ee.printStackTrace();

//TextField tf1,tf2;

}
public static void main(String[] args) {

new adminlogin();

You might also like