You are on page 1of 8

C:/Users/Teshager/Documents/NetBeansProjects/labtest/src/labtest/Labtest.

java

package labtest;
import java.awt.*;
import java.sql.*;
import java.awt .event.*;

import javax.swing.*;

public class Labtest implements ActionListener{


JLabel a,b;
JTextField un;
JPasswordField pw;
JButton b1;
JFrame f1;
public Labtest()
{
f1=new JFrame("Login");
a=new JLabel("User Name");
b=new JLabel("Password");

un=new JTextField(10);
pw=new JPasswordField(10);
b1=new JButton("Login");
b1.addActionListener(this);
f1.add(a);f1.add(un);
f1.add(b);f1.add(pw);f1.add(b1);
f1.setLayout(new FlowLayout());
f1.setSize(200,400);
f1.setVisible(true);
}
void login()
{
try
{
Connection con=DriverManager.getConnection("jdbc:mysql://localhost/hu","roo
Statement stmt=con.createStatement();
ResultSet rst=stmt.executeQuery("select * from tryu where username='"+un.ge
int c=0;
while(rst.next())
{

1.1 of 8 2022.06.14 13:53:07


C:/Users/Teshager/Documents/NetBeansProjects/labtest/src/labtest/Labtest.java

ysql://localhost/hu","root","");

u where username='"+un.getText()+"' and password='"+pw.getText()+"'");

1.2 of 8 2022.06.14 13:53:07


C:/Users/Teshager/Documents/NetBeansProjects/labtest/src/labtest/Labtest.java
c++;
}
stmt.close();
con.close();
if(c>0)
{
view();
}
else
{
JOptionPane.showMessageDialog(null, "LOGIN FAILD");
}
}
catch(Exception e2)
{
JOptionPane.showMessageDialog(null, e2);
}
}
void view()
{
try
{
Connection con=DriverManager.getConnection("jdbc:mysql://localhost/hu","roo
Statement stmt=con.createStatement();
ResultSet rst=stmt.executeQuery("select * from tryu ");
String hd[]={"Username","Password"};
String data[][]=new String[10][2];
int i=0;
while(rst.next())
{
data[i][0]=rst.getString("username");
data[i][1]=rst.getString("password");
i++;
}
JTable t1=new JTable(data,hd);
JScrollPane sp=new JScrollPane(t1);
f1=new JFrame("View");
f1.setLayout(new FlowLayout());
f1.setSize(400,400);
f1.add(sp);
f1.setVisible(true);

2.1 of 8 2022.06.14 13:53:07


C:/Users/Teshager/Documents/NetBeansProjects/labtest/src/labtest/Labtest.java

ysql://localhost/hu","root","");

2.2 of 8 2022.06.14 13:53:07


C:/Users/Teshager/Documents/NetBeansProjects/labtest/src/labtest/Labtest.java
stmt.close();
con.close();

}
catch(Exception e2)
{
JOptionPane.showMessageDialog(null, e2);
}
}
void register()
{
try
{
Connection con=DriverManager.getConnection("jdbc:mysql://localhost/hu","root
Statement stmt=con.createStatement();
int r=stmt.executeUpdate("insert into rtyu values('"+un.getText()+"','"+pw.
stmt.close();
con.close();
if(r>0)
{
JOptionPane.showMessageDialog(null, "REGISTER SUCESSFULLY");
}
else
{
JOptionPane.showMessageDialog(null, "REGISTRATION FAILD");
}
}
catch(Exception e2)
{
JOptionPane.showMessageDialog(null, e2);
}
}

3.1 of 8 2022.06.14 13:53:07


C:/Users/Teshager/Documents/NetBeansProjects/labtest/src/labtest/Labtest.java

sql://localhost/hu","root","");

'"+un.getText()+"','"+pw.getText()+"')");

SUCESSFULLY");

3.2 of 8 2022.06.14 13:53:07


C:/Users/Teshager/Documents/NetBeansProjects/labtest/src/labtest/Labtest.java

public void actionPerformed(ActionEvent e1)


{

login();

public static void main(String[] args) {

Labtest t1=new Labtest();

4.1 of 8 2022.06.14 13:53:07


C:/Users/Teshager/Documents/NetBeansProjects/labtest/src/labtest/Labtest.java

4.2 of 8 2022.06.14 13:53:07

You might also like