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

Program 1

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

Program 1

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

Prgram 1.

Write an Application for student Information system using JDBC and AWT

import javax.swing.*;

import java.awt.event.*;

import java.sql.*;

import java.awt.*;

public class StudInformation extends JFrame implements ActionListener

JTextField txt_id,txt_name,txt_age,txt_course,txt_semester,txt_tutor;

JLabel lbl_title,lbl_id,lbl_name,lbl_age,lbl_course,lbl_semester,lbl_tutor;

JButton btn_insert,btn_delete,btn_update,btn_clear,btn_search;

Connection c;

public StudInformation()

lbl_title=new JLabel("Student Information");

lbl_id=new JLabel("Id");

lbl_name=new JLabel("Name");

lbl_age=new JLabel("Age");

lbl_course=new JLabel("Course");

lbl_semester=new JLabel("Semester");

lbl_tutor=new JLabel("Tutor");

txt_id=new JTextField(20);

txt_name=new JTextField(20);

txt_age=new JTextField(20);

txt_course=new JTextField(20);

txt_semester=new JTextField(20);
txt_tutor=new JTextField(20);

btn_insert=new JButton("Insert");

btn_delete=new JButton("Delete");

btn_update=new JButton("Update");

btn_clear=new JButton("Clear");

btn_search=new JButton("Search");

btn_insert.addActionListener(this);

btn_delete.addActionListener(this);

btn_update.addActionListener(this);

btn_clear.addActionListener(this);

btn_search.addActionListener(this);

JPanel p1,p2,p3;

p1=new JPanel();

p1.setLayout(new FlowLayout());

p1.add(lbl_title);

p2=new JPanel();

p2.setLayout(new GridLayout(6,2));

p2.add(lbl_id);

p2.add(txt_id);

p2.add(lbl_name);

p2.add(txt_name);

p2.add(lbl_age);

p2.add(txt_age);

p2.add(lbl_course);
p2.add(txt_course);

p2.add(lbl_semester);

p2.add(txt_semester);

p2.add(lbl_tutor);

p2.add(txt_tutor);

p3=new JPanel();

p3.setLayout(new FlowLayout());

p3.add(btn_insert);

p3.add(btn_delete);

p3.add(btn_update);

p3.add(btn_clear);

p3.add(btn_search);

Container c=getContentPane();

c.setLayout(null);

p1.setBounds(20,20,300,40);

p2.setBounds(10,80,200,320);

p3.setBounds(10,400,300,80);

c.add(p1);

c.add(p2);

c.add(p3);

public void actionPerformed(ActionEvent ae)

{
try{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

c=DriverManager.getConnection("jdbc:odbc:stud");

catch(Exception ex)

String btn=ae.getActionCommand();

if(btn.equals("Clear"))

txt_id.setText("");

txt_name.setText("");

txt_age.setText("");

txt_course.setText("");

txt_semester.setText("");

txt_tutor.setText("");

if(btn.equals("Search"))

String id=txt_id.getText();

try{

String query1="Select *from stud where id='"+id+"'";

Statement st=c.createStatement();

ResultSet rs=st.executeQuery(query1);

while(rs.next())

txt_id.setText(rs.getString("id"));
txt_name.setText(rs.getString("name"));

txt_age.setText(rs.getString("age"));

txt_course.setText(rs.getString("course"));

txt_semester.setText(rs.getString("semester"));

txt_tutor.setText(rs.getString("tutor"));

catch(Exception ex)

if(btn.equals("Update"))

String s1=txt_id.getText();

String s2=txt_name.getText();

String s3=txt_age.getText();

String s4=txt_course.getText();

String s5=txt_semester.getText();

String s6=txt_tutor.getText();

try{

PreparedStatement ps=c.prepareStatement("Update stud set


id=?,name=?,age=?,course=?,semester=?,tutor=? where id=?");

ps.setString(1,s1);

ps.setString(2,s2);

ps.setString(3,s3);

ps.setString(4,s4);

ps.setString(5,s5);

ps.setString(6,s6);
ps.setString(7,s1);

ps.executeUpdate();

JOptionPane.showMessageDialog(null,"Successfully Updated");

txt_id.setText("");

txt_name.setText("");

txt_age.setText("");

txt_course.setText("");

txt_semester.setText("");

txt_tutor.setText("");

catch(Exception ex)

if(btn.equals("Delete"))

String s1=txt_id.getText();

try{

PreparedStatement ps=c.prepareStatement("Delete *from stud where id=?");

ps.setString(1,s1);

ps.executeUpdate();

JOptionPane.showMessageDialog(null,"Successfully deleted");

txt_id.setText("");

txt_name.setText("");

txt_age.setText("");

txt_course.setText("");

txt_semester.setText("");

txt_tutor.setText("");
}

catch(Exception ex)

if(btn.equals("Insert"))

String s1=txt_id.getText();

String s2=txt_name.getText();

String s3=txt_age.getText();

String s4=txt_course.getText();

String s5=txt_semester.getText();

String s6=txt_tutor.getText();

try{

PreparedStatement ps=c.prepareStatement("insert into stud


values(?,?,?,?,?,?)");

ps.setString(1,s1);

ps.setString(2,s2);

ps.setString(3,s3);

ps.setString(4,s4);

ps.setString(5,s5);

ps.setString(6,s6);

ps.executeUpdate();

JOptionPane.showMessageDialog(null,"Successfully Inserted");

txt_id.setText("");

txt_name.setText("");

txt_age.setText("");

txt_course.setText("");

txt_semester.setText("");
txt_tutor.setText("");

catch(Exception ex)

public static void main(String args[])

StudInformation stud=new StudInformation();

stud.setVisible(true);

stud.addWindowListener(new WindowAdapter()

public void windowClosing(WindowEvent e)

System.exit(0);

};

stud.setSize(new Dimension(400,520));

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy