You are on page 1of 5

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates


* and open the template in the editor.
*/
/**
*
* @author hp123
*/
import
import
import
import
import
import
import
import

javax.swing.JButton;
javax.swing.JFrame;
javax.swing.JLabel;
javax.swing.JOptionPane;
javax.swing.JScrollPane;
javax.swing.JTable;
javax.swing.JTextField;
javax.swing.table.DefaultTableModel;

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author H.P
*/
public class UpdateResult extends JFrame implements ActionListener
{
String str;
JFrame jf;
JTextField t1,t2,t3,t4,t5,t6,t7,t8,t9,tr,tq;
JLabel l1,l2,l3,l4,l5,l6,l7,l8,l9,l10;
JButton b0,b1,b2;
Font f;
Connection con;
PreparedStatement ps;
Statement stmt;
ResultSet rs;
DefaultTableModel model = new DefaultTableModel();
JTable tabGrid = new JTable(model);
JScrollPane scrlPane = new JScrollPane(tabGrid);

UpdateResult()
{
jf=new JFrame();
f = new Font("Times New Roman",Font.BOLD,20);
jf.setLayout(null);
l6=new JLabel("Update Result");
l6.setFont(new Font("Times New Roman",Font.BOLD,25));
l6.setBounds(250,50,300,40);l6.setForeground(Color.blue);
jf.add(l6);
l1= new JLabel("Student Adm No. ");

l1.setBounds(150,120,130,25);
jf.add(l1);
t1=new JTextField(20);
t1.setBounds(300,120,130,25);t1.setToolTipText("Enter Student ad
m no.");
jf.add(t1);
l2 = new JLabel("Student name*");
l2.setBounds(150,160,170,25);
jf.add(l2);
t2=new JTextField(20);
t2.setBounds(320,160,150,25);t2.setToolTipText("Enter Student na
me");
jf.add(t2);
l3 = new JLabel("Test Type*");
//l3.setFont(f);
l3.setBounds(150,200,170,25);
jf.add(l3);
t3=new JTextField(20);
t3.setBounds(320,200,150,25);t3.setToolTipText("test type");
jf.add(t3);
l4 = new JLabel("English Marks*");
//l4.setFont(f);
l4.setBounds(150,260,170,25);
jf.add(l4);
t4=new JTextField(20);
t4.setBounds(320,260,100,25);t4.setToolTipText("Enter english ma
rks");
jf.add(t4);
l5 = new JLabel("Hindi Marks*");
//l5.setFont(f);
l5.setBounds(150,280,170,25);
jf.add(l5);
t5=new JTextField(20);
t5.setBounds(320,280,100,25);t5.setToolTipText("Enter Hindi Mark
s");
jf.add(t5);
l7= new JLabel ("Maths Marks*");
l7.setBounds(150, 300, 170,25);
jf.add(l7);
t6= new JTextField(20);
t6.setBounds(320,300,100,25);t6.setToolTipText("enter maths mark
s");
jf.add(t6);
l8= new JLabel ("Science Marks*");
l8.setBounds(150, 320, 170,25);
jf.add(l8);
t7= new JTextField(20);

t7.setBounds(320,320,100,25);t6.setToolTipText("enter science ma
rks");
jf.add(t7);
l9= new JLabel ("Maximum Marks*");
l9.setBounds(150, 340, 170,25);
jf.add(l9);
t8= new JTextField(20);
t8.setBounds(320,340,100,25);t6.setToolTipText("enter Maximum ma
rks");
jf.add(t8);
l10= new JLabel ("Marks Obtained*");
l10.setBounds(150, 360, 170,25);
jf.add(l10);
t9= new JTextField(20);
t9.setBounds(320,360,100,25);t6.setToolTipText("enter marks obta
ined ");
jf.add(t9);

b0 = new JButton("open",new ImageIcon("images//save.png"));


b0.setBounds(500,400,110,35);b0.setToolTipText("click to save Student re
sult");
jf.add(b0);b0.addActionListener(this);
b1= new JButton("Update",new ImageIcon("images//save.png"));
b1.setBounds(700,400,110,35);b1.setToolTipText("click to open ");
jf.add(b1);b1.addActionListener(this);
b2= new JButton("clear",new ImageIcon("images//save.png"));
b2.setBounds(600,400,110,35);b2.setToolTipText("click to open ");
jf.add(b2);b2.addActionListener(this);
scrlPane.setBounds(0,500,900,600);
jf.add(scrlPane);
jf.setTitle("Update Result");
jf.setSize(900,700);
jf.setLocation(20,20);
jf.setResizable(false);
jf.getContentPane().setBackground(Color.white);
jf.setVisible(true);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==b0)
{
if(((t1.getText()).equals(""))&&((t2.getText()).equals("
")))
{
JOptionPane.showMessageDialog(this,"Please enter Student adm
no. or name !","Warning!!!",JOptionPane.WARNING_MESSAGE);
}
else

{//fetch
try
{
int foundrec = 0;
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/stu
dent","root","always");
System.out.println("Connected to database.");
ps=con.prepareStatement("select * from result where adm_no='"+t1.getTex
t()+"' or name='"+t2.getText()+"'");
rs=ps.executeQuery();
while(rs.next())
{
t1.setText(rs.getString(1));
t2.setText(rs.getString(2));
t3.setText(rs.getString(3));
t4.setText(rs.getString(4));
t5.setText(rs.getString(5));
t6.setText(rs.getString(5));t7.setText(rs.getString(5));
t8.setText(rs.getString(5));
t9.setText(rs.getString(5));
foundrec = 1;
}
if (foundrec == 0)
{
JOptionPane.showMessageDialog(null,"Record is not available"
,"Dialog",JOptionPane.WARNING_MESSAGE);
}
con.close();
}
catch(SQLException se)
{
System.out.println(se);
JOptionPane.showMessageDialog(null,"SQL Error:"+se);
}
catch(Exception e)
{
System.out.println(e);
JOptionPane.showMessageDialog(null,"Error:"+e);
}
}
}
if(ae.getSource()==b1)
{//update
try
{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/stu
dent","root","always");
System.out.println("Connected to database.");
stmt=con.createStatement();
String str1="UPDATE result SET adm_no='"+t1.getText()+"',name='"+t2.getText()+"'
,testtype='"+t3.getText()+"',english='"+t4.getText()+"',hindi='"+t5.getText()+"'

,maths='"+t6.getText()+"',science='"+t7.getText()+"',maxmarks='"+t8.getText()+"'
,marksobtained='"+t9.getText()+"' where adm_no='"+t1.getText()+"' or name='"+t2.
getText()+"' ";
stmt.executeUpdate(str1);
JOptionPane.showMessageDialog(null, "Record is updated");
t1.setText("");
t2.setText("");
t3.setText("");
t4.setText("");
t5.setText("");
t6.setText("");t7.setText("");t8.setText("");t9.setText("");
con.close();
}
catch(SQLException se)
{
System.out.println(se);
JOptionPane.showMessageDialog(null,"SQL Error:"+se);
}
catch(Exception e)
{
System.out.println(e);
JOptionPane.showMessageDialog(null,"Error:"+e);
}
}
}
public static void main(String arg[])
{
new UpdateResult();
}
}

You might also like