0% found this document useful (0 votes)
11 views2 pages

Answer For 5th Unit Program

Uploaded by

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

Answer For 5th Unit Program

Uploaded by

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

Unit 5

Part B
5. Explain the architecture of JDBC. Demonstrate how java application communicate
with database. (Hint : - Use swing)(Explain architecture from 4th unit and write the
below program)
9.Create student examination database system using swing and JDBC. Your database may
have the following student information such as registration number, name, marks in 6
subjects. Provide option for insert , delete and update student records.

Program:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class student extends JFrame implements ActionListener
{
JLabel l1,l2,l3;
JTextField tf1,tf2,tf3;
JButton btn1,btn2,btn3;
student()
{
setTitle("Login Form in Windows Form");
setVisible(true);
setSize(800, 800);
setLayout(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
l1 = new JLabel("register number");
l2 = new JLabel("Name");
l3 = new JLabel("oops mark");
tf1 = new JTextField();
tf2 = new JTextField();
tf3 = new JTextField();
btn1 = new JButton("Insert");
btn2 = new JButton("update");
btn3 = new JButton("delete");
add(l1);
add(l2);
add(l3);
add(tf1);
add(tf2);
add(tf3);
add(btn1);
add(btn2);
add(btn3);
setLayout(new flowLayout());
btn1.addActionListener(this);
btn2.addActionListener(this);
btn3.addActionListener(this);
setVisible(true);
setSize(600, 600);
setLayout(new flowLayout());
}
public void actionPerformed(ActionEvent e)
{
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection(
"jdbc:mysql://localhost:3306/st","root","root");
PreparedStatement stmt;
stmt=con.createStatement();
ResultSet rs;
if (e.getSource()==btn1)
{
stmt=con.prepareStatement("insert into stu values(tf1,tf2,tf3)");
int i =stmt.executeUpdate();
System.out.println(i+" records inserted");
}
else if(e.getSource()==btn2)
{
stmt=con.prepareStatement("update stu set mark=tf3 where reg=tf1");
int i=stmt.executeUpdate();
System.out.println(i+" records updated");
}
else
{
PreparedStatement stmt=con.prepareStatement("delete from stu where reg=tf1");
int i=stmt.executeUpdate();
System.out.println(i+" records deleted");
}
con.close();
}
catch(Exception e)
{
System.out.println("Error");
}
}
public static void main(string args[])
{
student l=new student();
}
}

You might also like