ArpanSingh

Code

Jul 5th, 2017
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. import java.awt.event.*;
  2. import javax.swing.*;
  3. import java.awt.*;
  4. import java.sql.*;
  5. class Admin implements ActionListener
  6. {
  7. JFrame f;
  8. JPanel p1;
  9. JLabel l1,l2,l3;
  10. JTextField t1,t2;
  11. JButton b1;
  12. Admin()
  13. {
  14. f=new JFrame("Admin");
  15. f.setSize(415,330);
  16. f.setResizable(false);
  17. f.setLocation(200,200);
  18. f.setLayout(null);
  19. f.setVisible(true);
  20. p1=new JPanel();
  21. p1.setBounds(0,0,420,50);
  22. p1.setBackground(Color.blue);
  23. f.add(p1);
  24. l1=new JLabel("STATE BANK OF INDIA");
  25. l1.setBounds(200,0,180,40);
  26. l1.setFont(new Font("Verdana",1,20));
  27. p1.add(l1);
  28. l2=new JLabel("User Name");
  29. l2.setBounds(60,80,100,30);
  30. f.add(l2);
  31. l3=new JLabel("Password");
  32. l3.setBounds(60,150,100,30);
  33. f.add(l3);
  34. t1=new JTextField();
  35. t1.setBounds(160,80,140,30);
  36. f.add(t1);
  37. t2=new JTextField();
  38. t2.setBounds(160,150,140,30);
  39. f.add(t2);
  40. b1=new JButton("Create Admin");
  41. b1.setBounds(160,210,140,30);
  42. b1.addActionListener(this);
  43. f.add(b1);
  44. f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  45. }
  46. public void actionPerformed(ActionEvent ae)
  47. {
  48. if(ae.getSource()==b1)
  49. {
  50. String s1=t1.getText();
  51. String s2=t2.getText();
  52. try
  53. {
  54. Class.forName("com.mysql.jdbc.Driver");
  55. Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/bank","root","");
  56. Statement stat=con.createStatement();
  57. stat.executeUpdate("insert into Admin values('"+s1+"','"+s2+"')");
  58. JOptionPane.showMessageDialog(null,"inserted ");
  59. t1.setText("");
  60. t2.setText("");
  61. }
  62. catch(Exception e1)
  63. {
  64. JOptionPane.showMessageDialog(null,"ERROR");
  65. }
  66. }
  67. }
  68.  
  69. public static void main(String args[])
  70. {
  71. new Admin();
  72.  
  73. }
  74. }
Add Comment
Please, Sign In to add comment