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

Java Program

java helpers

Uploaded by

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

Java Program

java helpers

Uploaded by

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

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);
Icon("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