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

📄 databasemanagerswing.java

📁 httptunnel.jar httptunnel java 源码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        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();            }            gResult.addRow(g);            System.out.println(l + " ms : " + sql);        }        g[0] = "" + total;        g[1] = "total";        g[2] = "";        gResult.addRow(g);        lTime = System.currentTimeMillis() - lTime;        updateResult();    }    /**     * Method declaration     *     */    private void showResultInText() {        String col[]  = gResult.getHead();        int    width  = col.length;        int    size[] = new int[width];        Vector data   = gResult.getData();        String row[];        int    height = data.size();        for (int i = 0; i < width; i++) {            size[i] = col[i].length();        }        for (int i = 0; i < height; i++) {            row = (String[]) data.elementAt(i);            for (int j = 0; j < width; j++) {                int l = row[j].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].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 = (String[]) data.elementAt(i);            for (int j = 0; j < width; j++) {                b.append(row[j]);                for (int l = row[j].length(); l <= size[j]; l++) {                    b.append(' ');                }            }            b.append(NL);        }        b.append(NL + height + " row(s) in " + lTime + " ms");        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);        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));/*// button replaced by toolbar        butExecute = new JButton("Execute");        butExecute.addActionListener(this);        pCommand.add(butExecute, BorderLayout.EAST);*/        pCommand.add(txtCommandScroll, BorderLayout.CENTER);        gResult      = new GridSwing();        gResultTable = new JTable(gResult);        gScrollPane  = new JScrollPane(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, 400));        tScrollPane.setMinimumSize(new Dimension(70, 100));        txtCommandScroll.setPreferredSize(new Dimension(360, 100));        txtCommandScroll.setMinimumSize(new Dimension(180, 100));        gScrollPane.setPreferredSize(new Dimension(460, 300));        ewSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,                                     tScrollPane, nsSplitPane);        fMain.getContentPane().add(ewSplitPane, BorderLayout.CENTER);        doLayout();        fMain.pack();    }    /* Simple tree node factory method - set's parent and user object.     */    private DefaultMutableTreeNode makeNode(Object userObject,            MutableTreeNode parent) {        DefaultMutableTreeNode node = new DefaultMutableTreeNode(userObject);        if (parent != null) {            treeModel.insertNodeInto(node, parent, parent.getChildCount());        }        return node;    }    /* Clear all existing nodes from the tree model and rebuild from scratch.     */    protected void refreshTree() {        DefaultMutableTreeNode propertiesNode;        DefaultMutableTreeNode leaf;        // First clear the existing tree by simply enumerating        // over the root node's children and removing them one by one.        while (treeModel.getChildCount(rootNode) > 0) {            DefaultMutableTreeNode child =                (DefaultMutableTreeNode) treeModel.getChild(rootNode, 0);            treeModel.removeNodeFromParent(child);            child.removeAllChildren();            child.removeFromParent();        }        treeModel.nodeStructureChanged(rootNode);        treeModel.reload();        tScrollPane.repaint();        // Now rebuild the tree below its root        try {            // Start by naming the root node from its URL:            rootNode.setUserObject(dMeta.getURL());            // get metadata about user tables by building a vector of table names            String    usertables[] = {                "TABLE", "GLOBAL TEMPORARY", "VIEW"            };            ResultSet result = dMeta.getTables(null, null, null, usertables);            Vector    tables       = new Vector();            // sqlbob@users Added remarks.            Vector remarks = new Vector();            while (result.next()) {                tables.addElement(result.getString(3));                remarks.addElement(result.getString(5));            }            result.close();            // For each table, build a tree node with interesting info            for (int i = 0; i < tables.size(); i++) {                String                 name = (String) tables.elementAt(i);                DefaultMutableTreeNode tableNode = makeNode(name, rootNode);                ResultSet col = dMeta.getColumns(null, null, name, null);                // sqlbob@users Added remarks.                String remark = (String) remarks.elementAt(i);                if ((remark != null) &&!remark.trim().equals("")) {                    makeNode(remark, tableNode);                }                // With a child for each column containing pertinent attributes                while (col.next()) {                    String c = col.getString(4);                    DefaultMutableTreeNode columnNode = makeNode(c,                        tableNode);                    String type = col.getString(6);                    makeNode("Type: " + type, columnNode);                    boolean nullable = col.getInt(11)                                       != DatabaseMetaData.columnNoNulls;                    makeNode("Nullable: " + nullable, columnNode);                }                col.close();                DefaultMutableTreeNode indexesNode = makeNode("Indices",                    tableNode);                ResultSet ind = dMeta.getIndexInfo(null, null, name, false,                                                   false);                String oldiname = null;                // A child node to contain each index - and its attributes                while (ind.next()) {                    DefaultMutableTreeNode indexNode = null;                    boolean                nonunique = ind.getBoolean(4);                    String                 iname     = ind.getString(6);                    if ((oldiname == null ||!oldiname.equals(iname))) {                        indexNode = makeNode(iname, indexesNode);                        makeNode("Unique: " + !nonunique, indexNode);                        oldiname = iname;                    }                    // And the ordered column list for index components                    makeNode(ind.getString(9), indexNode);                }                ind.close();            }            // Finally - a little additional metadata on this connection            propertiesNode = makeNode("Properties", rootNode);            makeNode("User: " + dMeta.getUserName(), propertiesNode);            makeNode("ReadOnly: " + cConn.isReadOnly(), propertiesNode);            makeNode("AutoCommit: " + cConn.getAutoCommit(), propertiesNode);            makeNode("Driver: " + dMeta.getDriverName(), propertiesNode);            makeNode("Product: " + dMeta.getDatabaseProductName(),                     propertiesNode);            makeNode("Version: " + dMeta.getDatabaseProductVersion(),                     propertiesNode);        } catch (SQLException se) {            propertiesNode = makeNode("Error getting metadata:", rootNode);            makeNode(se.getMessage(), propertiesNode);            makeNode(se.getSQLState(), propertiesNode);        }        treeModel.nodeStructureChanged(rootNode);        treeModel.reload();        tScrollPane.repaint();    }    protected JToolBar createToolBar() {        JToolBar jtoolbar = new JToolBar();        jtoolbar.putClientProperty("JToolBar.isRollover", Boolean.TRUE);        //---------------------------------------        JButton jbuttonClear = new JButton("Clear SQL Statement");        jbuttonClear.setToolTipText("Clear SQL Statement");        jbuttonClear.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent actionevent) {                clear();            }        });        //---------------------------------------        JButton jbuttonExecute = new JButton("Execute SQL Statement");        jbuttonExecute.setToolTipText("Execute SQL Statement");        jbuttonExecute.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent actionevent) {                execute();            }        });        jtoolbar.addSeparator();        jtoolbar.add(jbuttonClear);        jtoolbar.addSeparator();        jtoolbar.add(jbuttonExecute);        jtoolbar.addSeparator();        jbuttonClear.setAlignmentY(0.5F);        jbuttonClear.setAlignmentX(0.5F);        jbuttonExecute.setAlignmentY(0.5F);        jbuttonExecute.setAlignmentX(0.5F);        return jtoolbar;    }}

⌨️ 快捷键说明

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