⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 querytool.java

📁 一个用java写的开源的数据库系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    /**     * Method declaration     *     *     * @return     */    String getScript() {        try {            ResultSet    rResult = sStatement.executeQuery("SCRIPT");            StringBuffer a       = new StringBuffer();            while (rResult.next()) {                a.append(rResult.getString(1));                a.append('\n');            }            a.append('\n');            return a.toString();        } catch (SQLException e) {            return "";        }    }    /**     * Method declaration     *     *     * @return     */    String getImport() {        StringBuffer a        = new StringBuffer();        String       filename = "import.sql";        try {            BufferedReader in = new BufferedReader(new FileReader(filename));            String         line;            while ((line = in.readLine()) != null) {                a.append(line);                a.append('\n');            }            a.append('\n');            return a.toString();        } catch (Exception e) {            return "";        }    }    /**     * Adds a String to the Listbox of recent commands.     */    private void setRecent(String s) {        for (int i = 0; i < iMaxRecent; i++) {            if (s.equals(sRecent[i])) {                return;            }        }        if (sRecent[iRecent] != null) {            choRecent.remove(sRecent[iRecent]);        }        sRecent[iRecent] = s;        iRecent          = (iRecent + 1) % iMaxRecent;        choRecent.addItem(s);    }    String     sRecent[];    static int iMaxRecent = 24;    int        iRecent;    TextArea   txtCommand;    Button     butExecute, butScript;    Button     butImport;    Choice     choRecent;    Grid       gResult;    /**     * Create the graphical user interface. This is AWT code.     */    private void initGUI() {        // all panels        Panel pQuery       = new Panel();        Panel pCommand     = new Panel();        Panel pButton      = new Panel();        Panel pRecent      = new Panel();        Panel pResult      = new Panel();        Panel pBorderWest  = new Panel();        Panel pBorderEast  = new Panel();        Panel pBorderSouth = new Panel();        pQuery.setLayout(new BorderLayout());        pCommand.setLayout(new BorderLayout());        pButton.setLayout(new BorderLayout());        pRecent.setLayout(new BorderLayout());        pResult.setLayout(new BorderLayout());        pBorderWest.setBackground(SystemColor.control);        pBorderSouth.setBackground(SystemColor.control);        pBorderEast.setBackground(SystemColor.control);        // labels        Label lblCommand = new Label(" Command", Label.LEFT);        Label lblRecent  = new Label(" Recent", Label.LEFT);        Label lblResult  = new Label(" Result", Label.LEFT);        lblCommand.setBackground(SystemColor.control);        lblRecent.setBackground(SystemColor.control);        lblResult.setBackground(SystemColor.control);        // buttons        butExecute = new Button("Execute");        butScript  = new Button("Script");        butImport  = new Button("Import");        pButton.add("South", butScript);        pButton.add("Center", butExecute);        pButton.add("North", butImport);        // command - textarea        Font fFont = new Font("Dialog", Font.PLAIN, 12);        txtCommand = new TextArea(5, 40);        txtCommand.setFont(fFont);        // recent - choice        choRecent = new Choice();        // result - grid        gResult = new Grid();        // combine it        setLayout(new BorderLayout());        pRecent.add("Center", choRecent);        pRecent.add("North", lblRecent);        pCommand.add("North", lblCommand);        pCommand.add("East", pButton);        pCommand.add("Center", txtCommand);        pCommand.add("South", pRecent);        pResult.add("North", lblResult);        pResult.add("Center", gResult);        pQuery.add("North", pCommand);        pQuery.add("Center", pResult);        add("Center", pQuery);        add("West", pBorderWest);        add("East", pBorderEast);        add("South", pBorderSouth);        // fredt@users 20011210 - patch 450412 by elise@users        doLayout();    }    static String sTestData[] = {        "drop table Place if exists",        "create table Place (Code integer,Name varchar(255))",        "create index iCode on Place (Code)", "delete from place",        "insert into Place values (4900,'Langenthal')",        "insert into Place values (8000,'Zurich')",        "insert into Place values (3000,'Berne')",        "insert into Place values (1200,'Geneva')",        "insert into Place values (6900,'Lugano')",        "drop table Customer if exists",        "create table Customer (Nr integer,Name varchar(255),Place integer)",        "create index iNr on Customer (Nr)", "delete from Customer",        "insert into Customer values (1,'Meier',3000)",        "insert into Customer values (2,'Mueller',8000)",        "insert into Customer values (3,'Devaux',1200)",        "insert into Customer values (4,'Rossi',6900)",        "insert into Customer values (5,'Rickli',3000)",        "insert into Customer values (6,'Graf',3000)",        "insert into Customer values (7,'Mueller',4900)",        "insert into Customer values (8,'May',1200)",        "insert into Customer values (9,'Berger',8000)",        "insert into Customer values (10,'D''Ascoli',6900)",        "insert into Customer values (11,'Padruz',1200)",        "insert into Customer values (12,'Hug',4900)"    };    /**     * Method declaration     *     */    void insertTestData() {        for (int i = 0; i < sTestData.length; i++) {            try {                sStatement.executeQuery(sTestData[i]);            } catch (SQLException e) {                System.out.println("Exception: " + e);            }        }        setRecent("select * from place");        setRecent("select * from Customer");        setRecent("select * from Customer where place<>3000");        setRecent("select * from place where code>3000 or code=1200");        setRecent("select * from Customer where nr<=8\nand name<>'Mueller'");        setRecent("update Customer set name='Russi'\nwhere name='Rossi'");        setRecent("delete from Customer where place=8000");        setRecent("insert into place values(3600,'Thun')");        setRecent("drop index Customer.iNr");        setRecent("select * from Customer where name like '%e%'");        setRecent("select count(*),min(code),max(code),sum(code) from place");        String s = "select * from Customer,place\n"                   + "where Customer.place=place.code\n"                   + "and place.name='Berne'";        setRecent(s);        txtCommand.setText(s);        txtCommand.selectAll();    }    /**     * Method declaration     *     */    static void printHelp() {        System.out.println(            "Usage: java QueryTool [-options]\n" + "where options include:\n"            + "    -driver <classname>  name of the driver class\n"            + "    -url <name>          first part of the jdbc url\n"            + "    -database <name>     second part of the jdbc url\n"            + "    -user <name>         username used for connection\n"            + "    -password <name>     password for this user\n"            + "    -test <true/false>   insert test data\n"            + "    -log <true/false>    write log to system out");        System.exit(0);    }    /**     * Method declaration     *     *     * @param e     */    public void windowActivated(WindowEvent e) {}    /**     * Method declaration     *     *     * @param e     */    public void windowDeactivated(WindowEvent e) {}    /**     * Method declaration     *     *     * @param e     */    public void windowClosed(WindowEvent e) {}    /**     * Method declaration     *     *     * @param ev     */    public void windowClosing(WindowEvent ev) {        try {            cConn.close();        } catch (Exception e) {}        if (fMain != null) {            fMain.dispose();        }        System.exit(0);    }    /**     * Method declaration     *     *     * @param e     */    public void windowDeiconified(WindowEvent e) {}    /**     * Method declaration     *     *     * @param e     */    public void windowIconified(WindowEvent e) {}    /**     * Method declaration     *     *     * @param e     */    public void windowOpened(WindowEvent e) {}    /**     * Method declaration     *     *     * @param ev     */    public void actionPerformed(ActionEvent ev) {        String s = ev.getActionCommand();        if (s != null && s.equals("Exit")) {            windowClosing(null);        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -