Practical 12
Aim:- Develop a Graphical User Interface that performs the following SQL operations:
(a) Insert
(b) Delete
(c) Display.
import [Link].*;
import [Link].*;
import [Link].*;
public class pract12 extends Frame implements WindowListener,ActionListener
Frame f;
Button ad,de,cl;
TextField t1,t2,t3;
TextArea dis;
Label st;
int id[];
int age[];
int count=0;
String name[];
static String upt=null;
static String del=null;
static final String jdbc_Driver="[Link]";
static final String db_url="jdbc:mysql://localhost/emp";
static final String user="root";
static final String pass="kartik";
static Connection conn=null;
static Statement stmt=null;
public pract12(){
addWindowListener(this);
setLayout(new FlowLayout([Link]));
setTitle("MySQL Update");
setSize(500,500);
setVisible(true);
Label l1=new Label("ID=");
t1=new TextField(10);
Label l2=new Label("Age=");
t2=new TextField(10);
Label l3=new Label("Name=");
t3=new TextField(10);
ad=new Button("Add Query");
de=new Button("Del Query");
cl=new Button("Display");
[Link](this);
[Link](this);
[Link](this);
dis=new TextArea("Database:",10,50);
st=new Label("Status Bar ");
add(l1); add(t1);
add(l2); add(t2);
add(l3); add(t3);
add(ad); add(de);
add(cl); add(dis);
add(st);
public void con(){
try{[Link](jdbc_Driver);
[Link]("Connecting Databases...");
conn=[Link](db_url,user,pass);
[Link]("Connection ESTABLISHED...");
[Link]("Creating Statement...");
stmt=[Link]();
[Link]("Statement Created...");
catch(SQLException se)
[Link]();
catch(Exception e)
[Link]();
public void insrt(String a){
try{[Link](a);
[Link]("Query OK :)");
catch(SQLException se)
[Link]();
catch(Exception e)
[Link]();
public void delet(String a){
try{
[Link](a);
[Link]("Query OK :)");
catch(SQLException se)
[Link]();}
catch(Exception e)
[Link]();
public void disp(){
try
[Link]("Database:");
ResultSet rs;
rs=[Link]("Select Count(*) from Employees");
while([Link]()){
count=[Link](1);
id=new int[count];
age=new int[count];
name=new String[count];
rs=[Link]("Select * From Employees");
int i=0; while([Link]()){
id[i]=[Link]("id");
age[i]=[Link]("age");
name[i]=[Link]("name");
i++;
[Link]("Readed MySQL");
}
catch(SQLException se)
[Link]();
catch(Exception e)
[Link]();
public void windowOpened(WindowEvent we){
con();}
public void windowClosing(WindowEvent we){
setVisible(false);
[Link](0);
public void windowClosed(WindowEvent we){}
public void windowIconified(WindowEvent we){}
public void windowDeiconified(WindowEvent we){}
public void windowActivated(WindowEvent we){}
public void windowDeactivated(WindowEvent we){}
public void actionPerformed(ActionEvent ae)
if([Link]()=="Add Query"){
upt="Insert into Employees
value("+[Link]([Link]())+","
+[Link]([Link]())+",'"+[Link]()+"');";
insrt(upt);
if([Link]()=="Del Query")
{
del="delete from Employees where id="+[Link]([Link]());
delet(del);
if([Link]()=="Display"){
disp();
for(int i=0;i<count;i++){
[Link]("\nID:"+id[i]+" Name:"+name[i]+" Age"+age[i]);
public static void main(String []args){
new pract12();
Output:-
After query:-