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

📄 jtdscallablestatement.java

📁 第三方的SQL Server and Sybase的jdbc dirver,速度更快
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
// jTDS JDBC Driver for Microsoft SQL Server and Sybase// Copyright (C) 2004 The jTDS Project//// This library is free software; you can redistribute it and/or// modify it under the terms of the GNU Lesser General Public// License as published by the Free Software Foundation; either// version 2.1 of the License, or (at your option) any later version.//// This library 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// Lesser General Public License for more details.//// You should have received a copy of the GNU Lesser General Public// License along with this library; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA//package net.sourceforge.jtds.jdbc;import java.io.InputStream;import java.io.Reader;import java.math.BigDecimal;import java.net.URL;import java.net.MalformedURLException;import java.sql.Array;import java.sql.Blob;import java.sql.CallableStatement;import java.sql.Clob;import java.sql.Date;import java.sql.Ref;import java.sql.SQLException;import java.sql.Time;import java.sql.Timestamp;import java.util.Calendar;import java.util.Map;/** * jTDS implementation of the java.sql.CallableStatement interface. *<p> * Implementation note: * <ol> * <li>This class is a simple subclass of PreparedStatement and mainly adds support for * setting parameters. * <li>The class supports named parameters in a similar way to the * patch supplied by Tommy Sandstrom to the original jTDS code. * </ol> * * @author Mike Hutchinson * @version $Id: JtdsCallableStatement.java,v 1.16 2005/06/16 09:32:27 alin_sinpalean Exp $ */public class JtdsCallableStatement extends JtdsPreparedStatement implements CallableStatement {    /** Last parameter retrieved was null. */    protected boolean paramWasNull;    /**     * Construct a CallableStatement object.     *     * @param connection The connection owning this statement.     * @param sql The SQL statement specifying the procedure to call.     * @param resultSetType The result set type eg FORWARD_ONLY.     * @param concurrency   The result set concurrency eg READ_ONLY.     * @throws SQLException     */    JtdsCallableStatement(ConnectionJDBC2 connection, String sql, int resultSetType, int concurrency)        throws SQLException {        super(connection, sql, resultSetType, concurrency, false);    }    /**     * Find a parameter by name.     *     * @param name The name of the parameter to locate.     * @param set True if function is called from a set / register method.     * @return The parameter index as an <code>int</code>.     * @throws SQLException     */    int findParameter(String name, boolean set)        throws SQLException {        for (int i = 0; i < parameters.length; i++){            if (parameters[i].name != null && parameters[i].name.equalsIgnoreCase(name))                return i + 1;        }        if (set && !name.equalsIgnoreCase("@return_status")) {            for (int i = 0; i < parameters.length; i++){                if (parameters[i].name == null) {                    parameters[i].name = name;                    return i + 1;                }            }        }        throw new SQLException(Messages.get("error.callable.noparam", name), "07000");    }    /**     * Retrieve the value of an output parameter.     *     * @param parameterIndex the ordinal position of the parameter     * @return the parameter value as an <code>Object</code>     * @throws SQLException if the parameter has not been set     */    protected Object getOutputValue(int parameterIndex)            throws SQLException {        ParamInfo parameter = getParameter(parameterIndex);        if (!parameter.isOutput) {            throw new SQLException(                    Messages.get("error.callable.notoutput",                            new Integer(parameterIndex)),                    "07000");        }        Object value = parameter.getOutValue();        paramWasNull = (value == null);        return value;    }    /**     * Check that this statement is still open.     *     * @throws SQLException if statement closed.     */    protected void checkOpen() throws SQLException {        if (closed) {            throw new SQLException(                    Messages.get("error.generic.closed", "CallableStatement"), "HY010");        }    }// ---------- java.sql.CallableStatement methods follow ----------    public boolean wasNull() throws SQLException {        checkOpen();        return paramWasNull;    }    public byte getByte(int parameterIndex) throws SQLException {        return ((Integer) Support.convert(this, getOutputValue(parameterIndex), java.sql.Types.TINYINT, null)).byteValue();    }    public double getDouble(int parameterIndex) throws SQLException {        return ((Double) Support.convert(this, getOutputValue(parameterIndex), java.sql.Types.DOUBLE, null)).doubleValue();    }    public float getFloat(int parameterIndex) throws SQLException {        return ((Float) Support.convert(this, getOutputValue(parameterIndex), java.sql.Types.REAL, null)).floatValue();    }    public int getInt(int parameterIndex) throws SQLException {        return ((Integer) Support.convert(this, getOutputValue(parameterIndex), java.sql.Types.INTEGER, null)).intValue();    }    public long getLong(int parameterIndex) throws SQLException {        return ((Long) Support.convert(this, getOutputValue(parameterIndex), java.sql.Types.BIGINT, null)).longValue();    }    public short getShort(int parameterIndex) throws SQLException {        return ((Integer) Support.convert(this, getOutputValue(parameterIndex), java.sql.Types.SMALLINT, null)).shortValue();    }    public boolean getBoolean(int parameterIndex) throws SQLException {        return ((Boolean) Support.convert(this, getOutputValue(parameterIndex), BOOLEAN, null)).booleanValue();    }    public byte[] getBytes(int parameterIndex) throws SQLException {        return ((byte[]) Support.convert(this, getOutputValue(parameterIndex), java.sql.Types.VARBINARY, connection.getCharset()));    }    public void registerOutParameter(int parameterIndex, int sqlType) throws SQLException {        if (sqlType == java.sql.Types.DECIMAL            || sqlType == java.sql.Types.NUMERIC) {            registerOutParameter(parameterIndex, sqlType, -1);        } else {            registerOutParameter(parameterIndex, sqlType, 0);        }    }    public void registerOutParameter(int parameterIndex, int sqlType, int scale)        throws SQLException {        ParamInfo pi = getParameter(parameterIndex);        pi.isOutput = true;        if (Support.getJdbcTypeName(sqlType).equals("ERROR")) {            throw new SQLException(Messages.get("error.generic.badtype",                    Integer.toString(sqlType)), "HY092");        }        if (sqlType == java.sql.Types.CLOB) {            pi.jdbcType = java.sql.Types.LONGVARCHAR;        } else if (sqlType == java.sql.Types.BLOB) {            pi.jdbcType = java.sql.Types.LONGVARBINARY;        } else {            pi.jdbcType = sqlType;        }        pi.scale = scale;    }    public Object getObject(int parameterIndex) throws SQLException {        Object value = getOutputValue(parameterIndex);        // Don't return UniqueIdentifier objects as the user won't know how to        // handle them        if (value instanceof UniqueIdentifier) {            return value.toString();        }        // If the user requested String/byte[] instead of LOBs, do the conversion        if (!connection.getUseLOBs()) {            value = Support.convertLOB(value);        }        return value;    }    public String getString(int parameterIndex) throws SQLException {        return (String) Support.convert(this, getOutputValue(parameterIndex),                java.sql.Types.VARCHAR, connection.getCharset());    }    public void registerOutParameter(int parameterIndex, int sqlType, String typeName)        throws SQLException {        notImplemented("CallableStatement.registerOutParameter(int, int, String");    }    public byte getByte(String parameterName) throws SQLException {        return getByte(findParameter(parameterName, false));    }    public double getDouble(String parameterName) throws SQLException {        return getDouble(findParameter(parameterName, false));    }    public float getFloat(String parameterName) throws SQLException {        return getFloat(findParameter(parameterName, false));    }    public int getInt(String parameterName) throws SQLException {        return getInt(findParameter(parameterName, false));    }    public long getLong(String parameterName) throws SQLException {        return getLong(findParameter(parameterName, false));    }    public short getShort(String parameterName) throws SQLException {        return getShort(findParameter(parameterName, false));    }    public boolean getBoolean(String parameterName) throws SQLException {        return getBoolean(findParameter(parameterName, false));    }    public byte[] getBytes(String parameterName) throws SQLException {        return getBytes(findParameter(parameterName, false));    }    public void setByte(String parameterName, byte x) throws SQLException {        setByte(findParameter(parameterName, false), x);    }    public void setDouble(String parameterName, double x) throws SQLException {        setDouble(findParameter(parameterName, false), x);    }    public void setFloat(String parameterName, float x) throws SQLException {        setFloat(findParameter(parameterName, false), x);    }    public void registerOutParameter(String parameterName, int sqlType)        throws SQLException {        registerOutParameter(findParameter(parameterName, true), sqlType);    }

⌨️ 快捷键说明

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