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

📄 databasemanagerswing.java

📁 一個Light Weighted的Java Database Engin 適合各個領域之Java數据庫編輯.
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                gResult.setHead(g);                g[0] = "" + r;                gResult.addRow(g);            }            lTime = System.currentTimeMillis() - lTime;            if (sqlScriptBuffer == null) {                addToRecent(sql);                txtCommand.setEnabled(true); // clear() does this otherwise            } else {                clear();            }        } catch (SQLException e) {            lTime = System.currentTimeMillis() - lTime;            g[0]  = "SQL Error";            gResult.setHead(g);            String s = e.getMessage();            s    += " / Error Code: " + e.getErrorCode();            s    += " / State: " + e.getSQLState();            g[0] = s;            gResult.addRow(g);            //  Added: (weconsultants@users)            CommonSwing.errorMessage(e);            return;        }        if (autoRefresh) {            // We're already running in a "busy" thread.  Just update the            // status text.            setStatusLine("Refreshing object tree", 0);            String upper = sql.toUpperCase(Locale.ENGLISH);            // This test can be very liberal.  Too liberal will just do            // some extra refreshes.  Too conservative will display            // obsolete info.            if (upper.indexOf("ALTER") > -1 || upper.indexOf("DROP") > -1                    || upper.indexOf("CREATE") > -1) {                directRefreshTree();            }        }    }    /**     * Could somebody explain what the purpose of this method is?     * Contrary to the method name, it looks like it displays      * results only if gridFormat is off (seems like it  does     * nothing otherwise, except for clearing help text and moving focus).     */    private void updateResult() {        if (gridFormat) {            // in case 'help' has removed the grid            if (bHelp) {                pResult.removeAll();                pResult.add(gScrollPane, BorderLayout.CENTER);                pResult.doLayout();                gResult.fireTableChanged(null);                pResult.repaint();                bHelp = false;            }        } else {            showResultInText();        }        txtCommand.selectAll();        txtCommand.requestFocus();    }    /**     * We let Swing handle displaying nulls (which it generally does by     * printing nothing for them), except for the case of database     * VARCHARs, because this is the only class where there is any     * ambiguity about whether there is a null stored or not.     */    private void formatResultSet(ResultSet r) {        if (r == null) {            String[] g = new String[1];            g[0] = "Result";            gResult.setHead(g);            g[0] = "(empty)";            gResult.addRow(g);            return;        }        try {            ResultSetMetaData m         = r.getMetaData();            int               col       = m.getColumnCount();            Object[]          h         = new Object[col];            boolean[]         isVarChar = new boolean[col];            for (int i = 1; i <= col; i++) {                h[i - 1] = m.getColumnLabel(i);                isVarChar[i - 1] = (m.getColumnType(i)                                    == java.sql.Types.VARCHAR);            }            gResult.setHead(h);            while (r.next()) {                for (int i = 1; i <= col; i++) {                    try {                        h[i - 1] = r.getObject(i);                        if (r.wasNull()) {                            h[i - 1] = (isVarChar[i - 1] ? NULL_STR                                                         : null);                        }                    } catch (SQLException e) {}                }                gResult.addRow(h);            }            r.close();        } catch (SQLException e) {            //  Added: (weconsultants@users)            CommonSwing.errorMessage(e);        }    }    private void testPerformance() {        String       all   = txtCommand.getText();        StringBuffer b     = new StringBuffer();        long         total = 0;        for (int i = 0; i < all.length(); i++) {            char c = all.charAt(i);            if (c != '\n') {                b.append(c);            }        }        all = b.toString();        String[] g = new String[4];        g[0] = "ms";        g[1] = "count";        g[2] = "sql";        g[3] = "error";        gResult.setHead(g);        int max = 1;        lTime = System.currentTimeMillis() - lTime;        while (!all.equals("")) {            int    i = all.indexOf(';');            String sql;            if (i != -1) {                sql = all.substring(0, i);                all = all.substring(i + 1);            } else {                sql = all;                all = "";            }            if (sql.startsWith("--#")) {                max = Integer.parseInt(sql.substring(3));                continue;            } else if (sql.startsWith("--")) {                continue;            }            g[2] = sql;            long l = 0;            try {                l = DatabaseManagerCommon.testStatement(sStatement, sql, max);                total += l;                g[0]  = "" + l;                g[1]  = "" + max;                g[3]  = "";            } catch (SQLException e) {                g[0] = g[1] = "n/a";                g[3] = e.toString();                //  Added: (weconsultants@users)                CommonSwing.errorMessage(e);            }            gResult.addRow(g);            System.out.println(l + " ms : " + sql);        }        g[0] = "" + total;        g[1] = "total";        g[2] = "";        gResult.addRow(g);        lTime = System.currentTimeMillis() - lTime;    }    /**     * Method declaration     *     */    private void showResultInText() {        Object[] col   = gResult.getHead();        int      width = col.length;        int[]    size  = new int[width];        Vector   data  = gResult.getData();        Object[] row;        int      height = data.size();        for (int i = 0; i < width; i++) {            size[i] = col[i].toString().length();        }        for (int i = 0; i < height; i++) {            row = (Object[]) data.elementAt(i);            for (int j = 0; j < width; j++) {                String item = ((row[j] == null) ? ""                                                : row[j].toString());                int    l    = item.length();                if (l > size[j]) {                    size[j] = l;                }            }        }        StringBuffer b = new StringBuffer();        for (int i = 0; i < width; i++) {            b.append(col[i]);            for (int l = col[i].toString().length(); l <= size[i]; l++) {                b.append(' ');            }        }        b.append(NL);        for (int i = 0; i < width; i++) {            for (int l = 0; l < size[i]; l++) {                b.append('-');            }            b.append(' ');        }        b.append(NL);        for (int i = 0; i < height; i++) {            row = (Object[]) data.elementAt(i);            for (int j = 0; j < width; j++) {                String item = ((row[j] == null) ? ""                                                : row[j].toString());                b.append(item);                for (int l = item.length(); l <= size[j]; l++) {                    b.append(' ');                }            }            b.append(NL);        }        // b.append(NL + height + " row(s) in " + lTime + " ms");        // There is no reason why this report should be text-output-specific.         // Moving it to bottom of the setWaiting method (where the report        // gets written to the status line).        // I'm only doing the rowcount now.  Add the time report there if         // you are so inclined.         txtResult.setText(b.toString());    }    private void addToRecent(String s) {        for (int i = 0; i < iMaxRecent; i++) {            if (s.equals(sRecent[i])) {                return;            }        }        if (sRecent[iRecent] != null) {            mRecent.remove(iRecent);        }        sRecent[iRecent] = s;        if (s.length() > 43) {            s = s.substring(0, 40) + "...";        }        JMenuItem item = new JMenuItem(s);        item.setActionCommand("#" + iRecent);        item.addActionListener(this);        mRecent.insert(item, iRecent);        iRecent = (iRecent + 1) % iMaxRecent;    }    private void initGUI() {        JPanel pCommand = new JPanel();        pResult = new JPanel();        nsSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, pCommand,                                     pResult);        // Added: (weconsultants@users)        nsSplitPane.setOneTouchExpandable(true);        pCommand.setLayout(new BorderLayout());        pResult.setLayout(new BorderLayout());        Font fFont = new Font("Dialog", Font.PLAIN, 12);        txtCommand = new JTextArea(5, 40);        txtCommand.setMargin(new Insets(5, 5, 5, 5));        txtCommand.addKeyListener(this);        txtCommandScroll = new JScrollPane(txtCommand);        txtResult        = new JTextArea(20, 40);        txtResult.setMargin(new Insets(5, 5, 5, 5));        txtResultScroll = new JScrollPane(txtResult);        txtCommand.setFont(fFont);        txtResult.setFont(new Font("Courier", Font.PLAIN, 12));        pCommand.add(txtCommandScroll, BorderLayout.CENTER);        gResult = new GridSwing();        TableSorter sorter = new TableSorter(gResult);        tableModel   = sorter;        gResultTable = new JTable(sorter);        sorter.setTableHeader(gResultTable.getTableHeader());        gScrollPane = new JScrollPane(gResultTable);        gResultTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);        gResult.setJTable(gResultTable);        //getContentPane().setLayout(new BorderLayout());        pResult.add(gScrollPane, BorderLayout.CENTER);        // Set up the tree        rootNode    = new DefaultMutableTreeNode("Connection");        treeModel   = new DefaultTreeModel(rootNode);        tTree       = new JTree(treeModel);        tScrollPane = new JScrollPane(tTree);        tScrollPane.setPreferredSize(new Dimension(120, 4

⌨️ 快捷键说明

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