You are on page 1of 6

SEARCH CODE

try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con = (Connection)
DriverManager.getConnection("jdbc:mysql://localhost/susms","root","");
String qry ="select * from Students where ID='" +
txtSearch.getText() + "'" ;
Statement pst = (Statement) con.prepareStatement(qry);
ResultSet rs = pst.executeQuery(qry);

jTable1.setModel(net.proteanit.sql.DbUtils.resultSetToTableModel(rs));

}
catch (Exception e)
{
JOptionPane.showMessageDialog(this, e);
}
import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.Statement;

import javax.swing.JOptionPane;

Button Checking

try

Class.forName("com.mysql.jdbc.Driver");

Connection con = (Connection)


DriverManager.getConnection("jdbc:mysql://localhost/susms","root","");

String slct="select SQ from Users where name='"+txtname.getText()+"' ";

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

ResultSet rs;

rs=std.executeQuery(slct);

if(rs.next())

txtsecQ.setText(rs.getString("SQ"));
}

else

JOptionPane.showMessageDialog(null , "lama aqoonsana ciwaankaan");

catch (Exception e)

JOptionPane.showMessageDialog(null , e);

Button Forget

try

Class.forName("com.mysql.jdbc.Driver");

Connection con = (Connection)


DriverManager.getConnection("jdbc:mysql://localhost/susms","root","");

String slct="select Password from Users where SA='"+txtsecA.getText()+"' and name


='"+txtname.getText()+"'";

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

ResultSet rs;

rs=std.executeQuery(slct);

if(rs.next())

txtpass.setText(rs.getString("Password"));

else
{

JOptionPane.showMessageDialog(null , "Jawabtan lama aqonsana gali jawabta saxda ah");

txtsecA.setText("");

catch(Exception ex)

JOptionPane.showMessageDialog(null , ex);

Button Change Password

try {

int p=JOptionPane.showConfirmDialog(null, "Are you sure to Change","Change


",JOptionPane.YES_NO_OPTION);

if(p==0)

{
Class.forName("com.mysql.jdbc.Driver");

Connection con = (Connection)


DriverManager.getConnection("jdbc:mysql://localhost/susms","root","");

String sql="select * from users where name='"+ txtname.getText() +"' and password='"+
txtoldpass.getText() +"'";

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

ResultSet rs;

rs=std.executeQuery(sql);

if(!rs.next())

JOptionPane.showMessageDialog(this," Incorrect Username Or Password","Warning",2);

txtnewpass.setText("");

txtname.setText("");

else

String updte="UPDATE users set password='"+txtnewpass.getText()+"' where


name='"+txtname.getText()+"' and password='"+txtoldpass.getText()+"'";

std.executeUpdate(updte);

JOptionPane.showMessageDialog(null,"Password Changed Successfully","Update",1);

catch(Exception ex)

JOptionPane.showMessageDialog(null,ex);

You might also like