A Dvace Oop Lab Report Solved 5 4th Cs
A Dvace Oop Lab Report Solved 5 4th Cs
Hamza Nazir
(2872)
Submitted To:
Tasks:
Objective
Database Connectivity
Code:
Class
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
// getconnection();
/// createtable();
}
JFrame f;
JLabel l1;
JLabel l2;
JTextField t1;
JLabel l3;
JTextField t2;
JLabel l4;
JComboBox cb;
JLabel l5;
JTextField t3;
JButton b1;
JButton b2;
st_info()
{
f=new JFrame("SMS");
f.setSize(400,400);
l1=new JLabel("Student Mangment System");
l1.setBounds(50, 30, 200, 40);
f.add(l1);
/// Component
l2 = new JLabel("Std_id");
l2.setBounds(30, 80, 200, 40);
f.add(l2);
t1 = new JTextField();
t1.setBounds(100, 80, 200, 20);
f.add(t1);
//
//
//
l3 = new JLabel("Std_Name ");
l3.setBounds(30, 130, 200, 40);
f.add(l3);
t2 = new JTextField();
t2.setBounds(100, 130, 200, 20);
f.add(t2);
l4 = new JLabel("Std_degree");
l4.setBounds(30, 180, 200, 40);
f.add(l4);
/// combobox
t3 = new JTextField();
t3.setBounds(100, 230, 200, 40);
f.add(t3);
/// Button
f.setLayout(null);
f.setVisible(true);
String s_id;
String s_name;
String s_cgpa;
String s_degree;
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource()==b1)
{
s_id=t1.getText();
s_name=t2.getText();
s_cgpa=t3.getText();
s_degree= cb.getToolTipText();
Connection conn=getconnection();
try {
assert conn != null;
PreparedStatement insert=conn.prepareStatement( "INSERT INTO student_info(st_id,st_name,st_deg,st_gpa) VALUE(?,?,?,?)");
insert.setString(1,s_id );
insert.setString(2,s_name );
insert.setString(3,s_degree );
insert.setString(4,s_cgpa );
insert.executeUpdate();
System.out.println("insert selected");
} catch (Exception ex) {
System.out.println("execption in insertion ");
}
}
if (e.getSource()==b2)
{
}
}
create.executeUpdate();
} catch (Exception ex) {
System.out.println("execption in creation me ");
}
Output