Advertisement
Guest User

Untitled

a guest
Dec 1st, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. import java.awt.*;
  4. import java.awt.event.*;
  5. import javax.swing.*;
  6. import java.sql.*;
  7.  
  8. public class gui {
  9.  
  10. private static class HelloWorldDisplay extends JPanel {
  11. public void paintComponent(Graphics g) {
  12. super.paintComponent(g);
  13. g.drawString("Hello World", 20, 30);
  14. }
  15. }
  16.  
  17. private static class exitHandler implements ActionListener {
  18. public void actionPerformed(ActionEvent e) {
  19. System.exit(0);
  20. }
  21. }
  22. private static class addHandler implements ActionListener {
  23. public void actionPerformed(ActionEvent e) {
  24. System.exit(0);
  25. }
  26. }
  27. private static class dropHandler implements ActionListener {
  28. public void actionPerformed(ActionEvent e) {
  29. System.exit(0);
  30. }
  31. }
  32. private static class alterHandler implements ActionListener {
  33. public void actionPerformed(ActionEvent e) {
  34. System.exit(0);
  35. }
  36. }
  37. private static class viewHandler implements ActionListener {
  38. public void actionPerformed(ActionEvent e) {
  39. System.exit(0);
  40. }
  41. }
  42.  
  43.  
  44.  
  45. public static void main(String[] args) {
  46. try{
  47. //step1 load the driver class
  48. Class.forName("oracle.jdbc.driver.OracleDriver");
  49.  
  50. //step2 create the connection object
  51. Connection con=DriverManager.getConnection(
  52. "jdbc:oracle:thin:@localhost:1521:orcl","chyuen","124242466");
  53.  
  54. //step3 create the statement object
  55. Statement stmt=con.createStatement();
  56.  
  57. //step4 execute query
  58. ResultSet rs=stmt.executeQuery("select * from emp");
  59. while(rs.next())
  60. System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));
  61.  
  62. //step5 close the connection object
  63. con.close();
  64.  
  65. }catch(Exception e){ System.out.println(e);}
  66.  
  67. HelloWorldDisplay displayPanel = new HelloWorldDisplay();
  68. JButton addButton = new JButton("Create Tables");
  69. JButton dropButton = new JButton("Drop Tables");
  70. JButton alterButton = new JButton("Alter Tables");
  71. JButton viewButton = new JButton("View Tables");
  72. JButton exitButton = new JButton("Exit");
  73.  
  74. addHandler add = new addHandler();
  75. addButton.addActionListener(add);
  76.  
  77. dropHandler drop = new dropHandler();
  78. dropButton.addActionListener(drop);
  79.  
  80. alterHandler alter = new alterHandler();
  81. alterButton.addActionListener(alter);
  82.  
  83. viewHandler view = new viewHandler();
  84. viewButton.addActionListener(view);
  85.  
  86. exitHandler exit = new exitHandler();
  87. exitButton.addActionListener(exit);
  88.  
  89. JPanel content = new JPanel();
  90. content.setLayout(new GridLayout(5,1));
  91. content.add(addButton);
  92. content.add(dropButton);
  93. content.add(alterButton);
  94. content.add(viewButton);
  95. content.add(exitButton);
  96.  
  97. //SELECT table_name FROM user_tables
  98.  
  99.  
  100. JFrame window = new JFrame("Database GUI");
  101. window.setContentPane(content);
  102. window.setSize(250,400);
  103. window.setLocation(100,100);
  104. window.setVisible(true);
  105.  
  106.  
  107. }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement