Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- import java.sql.*;
- public class gui {
- 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);
- }
- }
- private static class addHandler implements ActionListener {
- public void actionPerformed(ActionEvent e) {
- System.exit(0);
- }
- }
- private static class dropHandler implements ActionListener {
- public void actionPerformed(ActionEvent e) {
- System.exit(0);
- }
- }
- private static class alterHandler implements ActionListener {
- public void actionPerformed(ActionEvent e) {
- System.exit(0);
- }
- }
- private static class viewHandler implements ActionListener {
- public void actionPerformed(ActionEvent e) {
- System.exit(0);
- }
- }
- public static void main(String[] args) {
- try{
- //step1 load the driver class
- Class.forName("oracle.jdbc.driver.OracleDriver");
- //step2 create the connection object
- Connection con=DriverManager.getConnection(
- "jdbc:oracle:thin:@localhost:1521:orcl","chyuen","124242466");
- //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();
- JButton addButton = new JButton("Create Tables");
- JButton dropButton = new JButton("Drop Tables");
- JButton alterButton = new JButton("Alter Tables");
- JButton viewButton = new JButton("View Tables");
- JButton exitButton = new JButton("Exit");
- addHandler add = new addHandler();
- addButton.addActionListener(add);
- dropHandler drop = new dropHandler();
- dropButton.addActionListener(drop);
- alterHandler alter = new alterHandler();
- alterButton.addActionListener(alter);
- viewHandler view = new viewHandler();
- viewButton.addActionListener(view);
- exitHandler exit = new exitHandler();
- exitButton.addActionListener(exit);
- 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);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement