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

📄 jdbcpreparedstatement.java

📁 这是linux下ssl vpn的实现程序
💻 JAVA
字号:
package com.sslexplorer.jdbc;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2004</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class JDBCPreparedStatement {

    String key;
    PreparedStatement ps;
    JDBCDatabaseEngine con;
    JDBCConnectionImpl impl;
    String sql;
    boolean transaction;

    JDBCPreparedStatement(String key,
                          String sql,
                          JDBCDatabaseEngine con,
                          JDBCConnectionImpl impl,
                          boolean transaction) throws SQLException {

        this.key = key;
        this.con = con;
        this.impl = impl;
        this.sql = sql;
        this.ps = impl.aquirePreparedStatement(key, sql);
        this.transaction = transaction;
    }
    
    public JDBCConnectionImpl getConnection() {
        return impl;
    }
    
    public void reprepare(String key, String sql) throws SQLException {
        if(this.ps != null) {
            impl.releasePreparedStatement(this.key, ps);            
        }
        this.key = key;
        this.sql = sql;
        this.ps = impl.aquirePreparedStatement(key, sql);
        reset();
    }

    public boolean execute() throws SQLException {
        return ps.execute();
    }

    public void reset() throws SQLException {
        ps.clearParameters();
    }

    public ResultSet executeQuery() throws SQLException {
        return ps.executeQuery();
            
    }

    public int executeUpdate() throws SQLException {
        return ps.executeUpdate();
            
    }

    public PreparedStatement getPreparedStatement() {
        return ps;
    }

    /**
     * Release the statement and the connection
     * 
     * @throws SQLException
     */
    public void releasePreparedStatement() throws SQLException {
        ps.clearParameters();
        impl.releasePreparedStatement(key, ps);
        if(!transaction) {
            con.releaseConnection(impl);
        }
    }

    public void setString(int idx, String str) throws SQLException {
        ps.setString(idx, str);
    }

    public void setNull(int idx, int parameterType) throws SQLException {
        ps.setNull(idx, parameterType);
    }

    public void setInt(int idx, int val) throws SQLException {
        ps.setInt(idx, val);
    }

    public void setLong(int idx, long val) throws SQLException {
        ps.setLong(idx, val);        
    }
    
    public String toString() {
        return ps.toString();
    }

    public void startTransaction() throws SQLException {
        if(transaction) {
            throw new SQLException("Transaction already started.");
        }
        transaction = true;
        impl.setAutoCommit(false);        
    }

    public void endTransaction() throws SQLException {
        if(!transaction) {
            throw new SQLException("Transaction already not started.");
        }
        transaction = false;
        impl.setAutoCommit(true);
        con.releaseConnection(impl);        
    }
    
    public void rollback() throws SQLException {
        impl.rollback();
    }
    
    public void commit() throws SQLException {
        impl.commit();
    }
}

⌨️ 快捷键说明

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