Guest User

Untitled

a guest
Aug 2nd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.98 KB | None | 0 0
  1. import java.sql.*;
  2. import javax.swing.*;
  3. import java.awt.*;
  4. import java.awt.event.*;
  5.  
  6. public class test1 extends JFrame implements ActionListener
  7. {
  8.     JTextField t;
  9.     JButton b;
  10.     test1()
  11.     {
  12.         super("Test");
  13.  
  14.         t = new JTextField(20);
  15.         b = new JButton("Save");
  16.  
  17.         JPanel p = new JPanel();
  18.  
  19.         p.add(t);
  20.         p.add(b);
  21.  
  22.         b.addActionListener(this);
  23.  
  24.         this.getContentPane().add(p);
  25.         this.setSize(300,200);
  26.         this.setVisible(true);
  27.     }
  28.  
  29.     public void actionPerformed(ActionEvent e)
  30.     {
  31.         if(e.getSource() == b)
  32.         {
  33.             String id = t.getText();
  34.             try
  35.             {
  36.                 Class.forName("oracle.jdbc.driver.OracleDriver");
  37.                 Connection conn = DriverManager.getConnection("jdbc:oracle:oci8:@", "scott", "tiger");
  38.                 Statement stmt = conn.createStatement();
  39.  
  40.                 stmt.executeUpdate("insert into emp(empno) values("+id+")");
  41.  
  42.                 stmt.close();
  43.                 conn.close();
  44.             }
  45.             catch(Exception er)
  46.             {
  47.             }
  48.         }
  49.     }
  50.  
  51.     public static void main (String [] args)
  52.     {
  53.         new test1();
  54.     }
  55.  }
Add Comment
Please, Sign In to add comment