import java.util.*; import java.io.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.sql.*; public class gui implements ActionListener { private static JButton addButton; private static JButton dropButton; private static JButton alterButton; private static JButton viewButton; private static JButton exitButton; //private static Connection con; public gui () { this.addButton = new JButton("Create Tables"); this.dropButton = new JButton("Drop Tables"); this.alterButton = new JButton("Alter Tables"); this.viewButton = new JButton("View Tables"); this.exitButton = new JButton("Exit"); this.addButton.addActionListener(this); this.dropButton.addActionListener(this); this.alterButton.addActionListener(this); this.viewButton.addActionListener(this); this.exitButton.addActionListener(this); } private static class HelloWorldDisplay extends JPanel { public void paintComponent(Graphics g) { super.paintComponent(g); g.drawString("Hello World", 20, 30); } } private static class exitHandler implements ActionListener { public void actionPerformed(ActionEvent e) { System.exit(0); } } public void actionPerformed(ActionEvent e) { if (e.getSource() == addButton) { try{ //step1 load the driver class Class.forName("oracle.jdbc.driver.OracleDriver"); //step2 create the connection object Connection con=DriverManager.getConnection( "jdbc:oracle:thin:@oracle.scs.ryerson.ca:1521:orcl","etkim","04229574"); Statement stmt = con.createStatement(); ResultSet rs=stmt.executeQuery(""); while(rs.next()) System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3)); //step5 close the connection object con.close(); }catch(Exception error){System.out.println(error);} } if (e.getSource() == viewButton) { try{ //step1 load the driver class Class.forName("oracle.jdbc.driver.OracleDriver"); //step2 create the connection object Connection con=DriverManager.getConnection( "jdbc:oracle:thin:@oracle.scs.ryerson.ca:1521:orcl","etkim","04229574"); Statement stmt = con.createStatement(); ResultSet rs=stmt.executeQuery("SELECT table_name FROM user_tables"); ResultSetMetaData rsmd = rs.getMetaData(); int columnsNumber = rsmd.getColumnCount(); while(rs.next()) { for (int i = 1; i <= columnsNumber; i++) { if (i > 1) System.out.print(", "); String columnValue = rs.getString(i); System.out.print(columnValue + " " + rsmd.getColumnName(i)); } System.out.println(""); } //step5 close the connection object con.close(); }catch(Exception error){System.out.println(error);} } } public static void main(String[] args) { gui g = new gui(); try{ //step1 load the driver class Class.forName("oracle.jdbc.driver.OracleDriver"); //step2 create the connection object Connection con=DriverManager.getConnection( "jdbc:oracle:thin:@oracle.scs.ryerson.ca:1521:orcl","etkim","04229574"); //step3 create the statement object Statement stmt=con.createStatement(); //step4 execute query ResultSet rs=stmt.executeQuery("select * from emp"); while(rs.next()) System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3)); //step5 close the connection object con.close(); }catch(Exception e){ System.out.println(e);} HelloWorldDisplay displayPanel = new HelloWorldDisplay(); JPanel content = new JPanel(); content.setLayout(new GridLayout(5,1)); content.add(addButton); content.add(dropButton); content.add(alterButton); content.add(viewButton); content.add(exitButton); //SELECT table_name FROM user_tables JFrame window = new JFrame("Database GUI"); window.setContentPane(content); window.setSize(250,400); window.setLocation(100,100); window.setVisible(true); } }