📄 preparedstatementwrapper.java
字号:
/* Copyright 2002-2007 MySQL AB, 2008 Sun Microsystems This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. There are special exceptions to the terms and conditions of the GPL as it is applied to this software. View the full text of the exception in file EXCEPTIONS-CONNECTOR-J in the directory of this software distribution. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */package com.mysql.jdbc.jdbc2.optional;import java.io.InputStream;import java.io.Reader;import java.lang.reflect.Constructor;import java.math.BigDecimal;import java.net.URL;import java.sql.Array;import java.sql.Blob;import java.sql.Clob;import java.sql.Date;import java.sql.ParameterMetaData;import java.sql.PreparedStatement;import java.sql.Ref;import java.sql.ResultSet;import java.sql.ResultSetMetaData;import java.sql.SQLException;import java.sql.Time;import java.sql.Timestamp;import java.util.Calendar;import com.mysql.jdbc.SQLError;import com.mysql.jdbc.Util;/** * Wraps prepared statements so that errors can be reported correctly to * ConnectionEventListeners. * * @author Mark Matthews * * @version $Id: PreparedStatementWrapper.java,v 1.1.2.1 2005/05/13 18:58:38 * mmatthews Exp $ */public class PreparedStatementWrapper extends StatementWrapper implements PreparedStatement { private static final Constructor JDBC_4_PREPARED_STATEMENT_WRAPPER_CTOR; static { if (Util.isJdbc4()) { try { JDBC_4_PREPARED_STATEMENT_WRAPPER_CTOR = Class.forName( "com.mysql.jdbc.jdbc2.optional.JDBC4PreparedStatementWrapper").getConstructor( new Class[] { ConnectionWrapper.class, MysqlPooledConnection.class, PreparedStatement.class }); } catch (SecurityException e) { throw new RuntimeException(e); } catch (NoSuchMethodException e) { throw new RuntimeException(e); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } } else { JDBC_4_PREPARED_STATEMENT_WRAPPER_CTOR = null; } } protected static PreparedStatementWrapper getInstance(ConnectionWrapper c, MysqlPooledConnection conn, PreparedStatement toWrap) throws SQLException { if (!Util.isJdbc4()) { return new PreparedStatementWrapper(c, conn, toWrap); } return (PreparedStatementWrapper) Util.handleNewInstance( JDBC_4_PREPARED_STATEMENT_WRAPPER_CTOR, new Object[] {c, conn, toWrap }); } PreparedStatementWrapper(ConnectionWrapper c, MysqlPooledConnection conn, PreparedStatement toWrap) { super(c, conn, toWrap); } /* * (non-Javadoc) * * @see java.sql.PreparedStatement#setArray(int, java.sql.Array) */ public void setArray(int parameterIndex, Array x) throws SQLException { try { if (this.wrappedStmt != null) { ((PreparedStatement) this.wrappedStmt).setArray(parameterIndex, x); } else { throw SQLError.createSQLException( "No operations allowed after statement closed", SQLError.SQL_STATE_GENERAL_ERROR); } } catch (SQLException sqlEx) { checkAndFireConnectionError(sqlEx); } } /* * (non-Javadoc) * * @see java.sql.PreparedStatement#setAsciiStream(int, java.io.InputStream, * int) */ public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException { try { if (this.wrappedStmt != null) { ((PreparedStatement) this.wrappedStmt).setAsciiStream( parameterIndex, x, length); } else { throw SQLError.createSQLException( "No operations allowed after statement closed", SQLError.SQL_STATE_GENERAL_ERROR); } } catch (SQLException sqlEx) { checkAndFireConnectionError(sqlEx); } } /* * (non-Javadoc) * * @see java.sql.PreparedStatement#setBigDecimal(int, java.math.BigDecimal) */ public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException { try { if (this.wrappedStmt != null) { ((PreparedStatement) this.wrappedStmt).setBigDecimal( parameterIndex, x); } else { throw SQLError.createSQLException( "No operations allowed after statement closed", SQLError.SQL_STATE_GENERAL_ERROR); } } catch (SQLException sqlEx) { checkAndFireConnectionError(sqlEx); } } /* * (non-Javadoc) * * @see java.sql.PreparedStatement#setBinaryStream(int, java.io.InputStream, * int) */ public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException { try { if (this.wrappedStmt != null) { ((PreparedStatement) this.wrappedStmt).setBinaryStream( parameterIndex, x, length); } else { throw SQLError.createSQLException( "No operations allowed after statement closed", SQLError.SQL_STATE_GENERAL_ERROR); } } catch (SQLException sqlEx) { checkAndFireConnectionError(sqlEx); } } /* * (non-Javadoc) * * @see java.sql.PreparedStatement#setBlob(int, java.sql.Blob) */ public void setBlob(int parameterIndex, Blob x) throws SQLException { try { if (this.wrappedStmt != null) { ((PreparedStatement) this.wrappedStmt).setBlob(parameterIndex, x); } else { throw SQLError.createSQLException( "No operations allowed after statement closed", SQLError.SQL_STATE_GENERAL_ERROR); } } catch (SQLException sqlEx) { checkAndFireConnectionError(sqlEx); } } /* * (non-Javadoc) * * @see java.sql.PreparedStatement#setBoolean(int, boolean) */ public void setBoolean(int parameterIndex, boolean x) throws SQLException { try { if (this.wrappedStmt != null) { ((PreparedStatement) this.wrappedStmt).setBoolean( parameterIndex, x); } else { throw SQLError.createSQLException( "No operations allowed after statement closed", SQLError.SQL_STATE_GENERAL_ERROR); } } catch (SQLException sqlEx) { checkAndFireConnectionError(sqlEx); } } /* * (non-Javadoc) * * @see java.sql.PreparedStatement#setByte(int, byte) */ public void setByte(int parameterIndex, byte x) throws SQLException { try { if (this.wrappedStmt != null) { ((PreparedStatement) this.wrappedStmt).setByte(parameterIndex, x); } else { throw SQLError.createSQLException( "No operations allowed after statement closed", SQLError.SQL_STATE_GENERAL_ERROR); } } catch (SQLException sqlEx) { checkAndFireConnectionError(sqlEx); } } /* * (non-Javadoc) * * @see java.sql.PreparedStatement#setBytes(int, byte[]) */ public void setBytes(int parameterIndex, byte[] x) throws SQLException { try { if (this.wrappedStmt != null) { ((PreparedStatement) this.wrappedStmt).setBytes(parameterIndex, x); } else { throw SQLError.createSQLException( "No operations allowed after statement closed", SQLError.SQL_STATE_GENERAL_ERROR); } } catch (SQLException sqlEx) { checkAndFireConnectionError(sqlEx); } } /* * (non-Javadoc) * * @see java.sql.PreparedStatement#setCharacterStream(int, java.io.Reader, * int) */ public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException { try { if (this.wrappedStmt != null) { ((PreparedStatement) this.wrappedStmt).setCharacterStream( parameterIndex, reader, length); } else { throw SQLError.createSQLException( "No operations allowed after statement closed", SQLError.SQL_STATE_GENERAL_ERROR); } } catch (SQLException sqlEx) { checkAndFireConnectionError(sqlEx); } } /* * (non-Javadoc) * * @see java.sql.PreparedStatement#setClob(int, java.sql.Clob) */ public void setClob(int parameterIndex, Clob x) throws SQLException { try { if (this.wrappedStmt != null) { ((PreparedStatement) this.wrappedStmt).setClob(parameterIndex, x); } else { throw SQLError.createSQLException( "No operations allowed after statement closed", SQLError.SQL_STATE_GENERAL_ERROR); } } catch (SQLException sqlEx) { checkAndFireConnectionError(sqlEx); } } /* * (non-Javadoc) * * @see java.sql.PreparedStatement#setDate(int, java.sql.Date) */ public void setDate(int parameterIndex, Date x) throws SQLException { try { if (this.wrappedStmt != null) { ((PreparedStatement) this.wrappedStmt).setDate(parameterIndex, x); } else { throw SQLError.createSQLException( "No operations allowed after statement closed", SQLError.SQL_STATE_GENERAL_ERROR); } } catch (SQLException sqlEx) { checkAndFireConnectionError(sqlEx); } } /* * (non-Javadoc) * * @see java.sql.PreparedStatement#setDate(int, java.sql.Date, * java.util.Calendar) */ public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException { try { if (this.wrappedStmt != null) { ((PreparedStatement) this.wrappedStmt).setDate(parameterIndex, x, cal); } else { throw SQLError.createSQLException( "No operations allowed after statement closed", SQLError.SQL_STATE_GENERAL_ERROR); } } catch (SQLException sqlEx) { checkAndFireConnectionError(sqlEx); } } /* * (non-Javadoc) * * @see java.sql.PreparedStatement#setDouble(int, double) */ public void setDouble(int parameterIndex, double x) throws SQLException { try { if (this.wrappedStmt != null) { ((PreparedStatement) this.wrappedStmt).setDouble( parameterIndex, x); } else { throw SQLError.createSQLException( "No operations allowed after statement closed", SQLError.SQL_STATE_GENERAL_ERROR); } } catch (SQLException sqlEx) { checkAndFireConnectionError(sqlEx); } } /* * (non-Javadoc) * * @see java.sql.PreparedStatement#setFloat(int, float) */ public void setFloat(int parameterIndex, float x) throws SQLException { try { if (this.wrappedStmt != null) { ((PreparedStatement) this.wrappedStmt).setFloat(parameterIndex, x); } else { throw SQLError.createSQLException( "No operations allowed after statement closed", SQLError.SQL_STATE_GENERAL_ERROR); } } catch (SQLException sqlEx) { checkAndFireConnectionError(sqlEx); } } /* * (non-Javadoc) * * @see java.sql.PreparedStatement#setInt(int, int) */ public void setInt(int parameterIndex, int x) throws SQLException { try { if (this.wrappedStmt != null) { ((PreparedStatement) this.wrappedStmt) .setInt(parameterIndex, x); } else { throw SQLError.createSQLException( "No operations allowed after statement closed", SQLError.SQL_STATE_GENERAL_ERROR); } } catch (SQLException sqlEx) { checkAndFireConnectionError(sqlEx); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -