You are on page 1of 3

import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.sql.

*; class app implements ActionListener { JFrame fr; JLabel id,name,salary; JButton save,show,delete,update; JPanel p,p1; JTextField t1,t2,t3; app() { fr=new JFrame(); t1=new JTextField(); t2=new JTextField(); t3=new JTextField(); id=new JLabel("id"); name=new JLabel("name"); salary=new JLabel("salary"); save=new JButton("save"); show=new JButton("show"); delete=new JButton("delete"); update=new JButton("update"); p=new JPanel(); p.setLayout(null); name.setBounds(100,60,40,60); salary.setBounds(100,90,40,60); id.setBounds(100,30,40,60); t1.setBounds(180,40,60,30); t2.setBounds(180,75,60,30); t3.setBounds(180,110,60,30); save.addActionListener(this); show.addActionListener(this); delete.addActionListener(this); update.addActionListener(this); p.add(name); p.add(salary); p.add(id); p.add(t1); p.add(t2); p.add(t3); fr.add(p,BorderLayout.CENTER); p1=new JPanel(); p1.setLayout(new FlowLayout()); p1.add(save); p1.add(show); p1.add(update); p1.add(delete); fr.add(p1,BorderLayout.SOUTH); fr.setSize(400,400); fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); fr.setVisible(true); } public void actionPerformed(ActionEvent d) { if(d.getSource()==save) {}

else if(d.getSource()==show) { c ob=new c(); if(ob.show(t1.getText())) { t2.setText(ob.empname); t2.setText(String.valueOf(ob.empsalary)); } else { JOptionPane.showMessageDialog(t2,"Record not Fou nd"); } } else if(d.getSource()==update) { } else{ } } public static void main(String ar[]) { new app(); } } class c { public String empname; public int empsalary; Connection con=null; public c() { try { System.out.println("hello:"); Class.forName("oracle.jdbc.driver.OracleDriver"); System.out.println("driver load"); con=DriverManager.getConnection("jdbc:oracle:thin:@local host:1521:XE","daman","damanghai409"); System.out.println("connection maintain"); }catch(Exception f){ System.out.println("Driver error"); } } public boolean show(String id) { boolean flag=false; try { PreparedStatement pst=con.prepareStatement("select * fro m emp1 where id=?");

pst.setInt(1,Integer.parseInt(id)); ResultSet set=pst.executeQuery(); if(set.next()) { empname=set.getString(2); empsalary=set.getInt(3); flag=true; } set.close(); con.close(); }catch(Exception g) { System.out.println(g.getMessage()); } return flag; } }

You might also like