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

📄 jdbcconnection.java

📁 一个用java写的开源的数据库系统
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     *  sent to the database; may contain one or more ?     *  parameters. <p>     *     *  <B>Note:</B> Typically the SQL statement is a JDBC     *  function call escape string.     * @return a new default <code>CallableStatement</code> object     *  containing the pre-compiled SQL statement     * @exception SQLException if a database access error occurs <p>     * @see #prepareCall(String,int,int)     */    public CallableStatement prepareCall(String sql) throws SQLException {        if (Trace.TRACE) {            Trace.trace(sql);        }        checkClosed();        return new jdbcPreparedStatement(this, sql);    }    /**     * <!-- start generic documentation -->     * Converts the given SQL statement     * into the system's native SQL grammar. A driver may convert the     * JDBC SQL grammar into its system's native SQL grammar prior to     * sending it. This method returns the native form of the     * statement that the driver would have sent. <p>     *     * <!-- end generic documentation -->     * <!-- start release-specific documentation -->     * <span class="ReleaseSpecificDocumentation">     * <b>HSQLDB-Specific Information:</b> <p>     *     * Up to and including 1.7.1, HSQLDB converts the JDBC SQL     * grammar into the system's native SQL grammar prior to sending     * it; this method returns the native form of the statement that     * the driver would send in place of client-specified JDBC SQL     * grammar. <p>     *     * </span> <!-- end release-specific documentation -->     *     * @param sql a SQL statement that may contain one or more '?'     *     parameter placeholders     * @return the native form of this statement     * @throws SQLException if a database access error occurs <p>     */    public String nativeSQL(String sql) throws SQLException {        checkClosed();        if (sql.indexOf('{') == -1) {            return sql;        }        char    s[]     = sql.toCharArray();        boolean changed = false;        int     state   = 0;        int     len     = s.length;        for (int i = 0; i < len; i++) {            char c = s[i];            switch (state) {                case 0 :    // normal                    if (c == '\'') {                        state = 1;                    } else if (c == '"') {                        state = 2;                    } else if (c == '{') {                        s[i]    = ' ';                        changed = true;                        String sub = sql.substring(i + 1).toUpperCase();                        if (sub.startsWith("?=")) {                            i += 2;                        } else if (sub.startsWith("CALL")) {                            i += 4;                        } else if (sub.startsWith("ESCAPE")) {                            i += 6;                        }                        state = 3;                    }                    break;                case 1 :    // inside ' '                case 5 :    // inside { } and ' '                    if (c == '\'') {                        state -= 1;                    }                    break;                case 2 :    // inside " "                case 6 :    // inside { } and " "                    if (c == '"') {                        state -= 2;                    }                    break;                case 3 :    // inside { } before whitespace                    if (c == ' ') {                        state = 4;                    } else {                        s[i]    = ' ';                        changed = true;                    }                    break;                case 4 :    // inside { } after whitespace                    if (c == '\'') {                        state = 5;                    } else if (c == '"') {                        state = 6;                    } else if (c == '}') {                        s[i]    = ' ';                        changed = true;                        state   = 0;                    }            }        }        if (changed) {            sql = new String(s);            if (Trace.TRACE) {                Trace.trace(s + " > " + sql);            }        }        return sql;    }    /**     * <!-- start generic documentation -->     * Sets this connection's auto-commit mode to the given state.     * If a connection is in auto-commit mode, then all its SQL     * statements will be executed and committed as individual transactions.     * Otherwise, its SQL statements are grouped into transactions that     * are terminated by a call to either the method <code>commit</code> or     * the method <code>rollback</code>. By default, new connections are     * in auto-commit mode. <p>     *     * The commit occurs when the statement completes or the next     * execute occurs, whichever comes first. In the case of     * statements returning a <code>ResultSet</code> object, the     * statement completes when the last row of the <code>ResultSet</code>     * object has been retrieved or the <code>ResultSet</code> object     * has been closed. In advanced cases, a single statement may     * return multiple results as well as output parameter values. In     * these cases, the commit occurs when all results and output     * parameter values have been retrieved. <p>     *     * <B>NOTE:</B> If this method is called during a transaction,     * the transaction is committed. <p>     *     * <!-- end generic documentation -->     * <!-- start release-specific documentation -->     * <span class="ReleaseSpecificDocumentation">     * <b>HSQLDB-Specific Information:</b> <p>     *     * Up to and including HSQLDB 1.7.0, <p>     *     *     * <OL>     *   <LI> All rows of a result set are retrieved internally <I>     *   before</I> the first row can actually be fetched.<br>     *   Therefore, a statement can be considered complete as soon as     *   any XXXStatement.executeXXX method returns. </LI>     *   <LI> Multiple result sets and output parameters are not yet     *   supported. </LI>     * </OL>     * <p>     *     * (boucherb@users) </span> <!-- end release-specific     * documentation -->     *     * @param autoCommit <code>true</code> to enable auto-commit     *     mode; <code>false</code> to disable it     * @exception SQLException if a database access error occurs     * @see #getAutoCommit     */    public void setAutoCommit(boolean autoCommit) throws SQLException {        execute("SET AUTOCOMMIT " + (autoCommit ? "TRUE"                                                : "FALSE"));    }    /**     *  Gets the current auto-commit state.     *     * @return  the current state of auto-commit mode     * @exception  SQLException Description of the Exception     * @see  #setAutoCommit     */    public boolean getAutoCommit() throws SQLException {        // comment        // Test properly if new code works correctly        // fredt@users 20020510        if (Trace.TRACE) {            Trace.trace();        }        if (iType == INTERNAL || iType == STANDALONE) {            return cSession.getAutoCommit();        } else {            try {                ResultSet rs =                    execute("call \"org.hsqldb.Library.getAutoCommit\"()");                rs.next();                return rs.getBoolean(1);            } catch (SQLException e) {                this.close();                throw Trace.error(Trace.CONNECTION_IS_BROKEN);            }        }    }    /**     * <!-- start generic documentation -->     * Makes all changes made since the     * previous commit/rollback permanent and releases any database     * locks currently held by the Connection. This method should be     * used only when auto-commit mode has been disabled. <p>     *     * <!-- end generic documentation -->     * <!-- start release-specific documentation -->     * <span class="ReleaseSpecificDocumentation">     * <b>HSQLDB-Specific Information:</b> <p>     *     * As of HSQLDB 1.7.0, SQL Savepoints are supported.  As such,     * successfully calling this method now also removes all     * Savepoints from this connection's {@link Session Session}. <p>     *     * Up to 1.6.1, HSQLDB did not support Savepoints in     * transactions, named or anonymous. <p>     *     * As of 1.7.0, HSQLDB supports an arbitrary number of named     * Savepoints per transaction and allows explicitly rolling back     * to any one of them. At this time, HSQLDB does not support     * anonymous Savepoints. However, this feature <i>is</i> slated     * for the 1.7.x series. <p>     *     * Also, JDBC 3 support for java.sql.Savepoint has not yet been     * implemented. At present, rather, the following SQL syntax must     * be used: <p>     *     * <code class="JavaCodeExample">     * SAVEPOINT savepoint_name1;<br>     * ... -- perform some work<br>     * SAVEPOINT savepoint_name2;<br>     * ...-- perform some work<br>     * ROLLABACK TO SAVEPOINT savepoint_name2<br>     * ...-- perform some work<br>     * ROLLABACK TO SAVEPOINT savepoint_name1; </code> <p>     *     * <B>Note:</B> If two or more Savepoints with the same name are     * performed during the same transaction, the latest one replaces     * the previous one, so that it is impossible to roll back to the     * previous one. </span> <p>     *     * <!-- end release-specific documentation -->     *     * @exception SQLException if a database access error occurs     * @see #setAutoCommit     */    public void commit() throws SQLException {        execute("COMMIT");    }    /**     * <!-- start generic documentation -->     * Drops all changes made since the     * previous commit/rollback and releases any database locks     * currently held by this Connection. This method should be used     * only when auto- commit has been disabled. <p>     *     * <!-- end generic documentation -->     * <!-- start release-specific documentation -->     * <span class="ReleaseSpecificDocumentation">     * <b>HSQLDB-Specific Information:</b> <p>     *     * As of HSQLDB 1.7.0, SQL Savepoints are supported.  As such,     * successfully calling this method also removes all Savepoints     * from this <code>Connection</code>'s {@link Session Session}.     * <p>     *     * Up to 1.6.1, HSQLDB did not support Savepoints in     * transactions, named or anonymous. <p>     *     * As of 1.7.0, HSQLDB supports an arbitrary number of named     * Savepoints per transaction and allows explicitly rolling back     * to any one of them. At this time, HSQLDB does not support     * anonymous Savepoints. However, this feature <i>is</i> slated     * for the 1.7.x series. <p>     *     * Also, as of 1.7.0, JDBC 3 support for java.sql.Savepoint has     * not yet been implemented. At present, rather, the following     * SQL syntax must be used: <p>     *     * <code class="JavaCodeExample">     * SAVEPOINT savepoint_name1;<br>     * ...-- perform some work<br>     * SAVEPOINT savepoint_name2;<br>     * ...-- perform some work<br>     * ROLLABACK TO SAVEPOINT savepoint_name2<br>     * ...-- perform some work<br>     * ROLLABACK TO SAVEPOINT savepoint_name1; </code> <p>     *     * <code>Note:</code> If two or more Savepoints with the same     * name are performed during the same transaction, the latest one     * replaces the previous one, making it impossible to roll back     * to the previous one. </span> <p>     *     * <!-- end release-specific documentation -->     *     * @exception SQLException if a database access error occurs     * @see #setAutoCommit     */    public void rollback() throws SQLException {        execute("ROLLBACK");    }    /**     * <!-- start generic documentation -->     * Releases this <code>Connection</code>

⌨️ 快捷键说明

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