提交 5c69455f authored 作者: Thomas Mueller's avatar Thomas Mueller

Various CallableStatement methods could throw a NullPointerException.

上级 52f3bd34
......@@ -18,8 +18,12 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>LOB files were not deleted when running DROP ALL OBJECTS.
<ul><li>Various CallableStatement methods could throw a NullPointerException.
</li><li>LOB files were not deleted when running DROP ALL OBJECTS.
</li><li>MS SQL Server compatibility: support string literals prefixed with N ("National Language" strings). Issue 240.
</li><li>CAST: when converting a string to binary, it is hex encoded (every byte two characters);
a hex string can be converted to a number by first converting it to binary. Examples:
CAST(CAST('FFFF' AS BINARY) AS INT) = 65535, CAST(65535 AS BINARY) = '0000FFFF'.
</li><li>When a domain (user defined data type) contained a user defined function, the database could not be opened.
</li><li>CAST('011' AS INT) will no longer use decode the value as an octal number (using Integer.decode) but now use Integer.parseInt.
The same logic applied to byte, short, and long. This also means that trying to convert hex numbers (0x...) with CAST now fails.
......
......@@ -28,10 +28,12 @@ import java.sql.Timestamp;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
import org.h2.constant.ErrorCode;
import org.h2.expression.ParameterInterface;
import org.h2.message.DbException;
import org.h2.message.TraceObject;
import org.h2.util.BitField;
import org.h2.util.New;
import org.h2.value.ValueNull;
/**
......@@ -44,7 +46,7 @@ public class JdbcCallableStatement extends JdbcPreparedStatement implements Call
private BitField outParameters;
private int maxOutParameters;
private Map<String, Integer> namedParameters;
private HashMap<String, Integer> namedParameters;
JdbcCallableStatement(JdbcConnection conn, String sql, int id, int resultSetType, int resultSetConcurrency) {
super(conn, sql, id, resultSetType, resultSetConcurrency, false);
......@@ -68,455 +70,1129 @@ public class JdbcCallableStatement extends JdbcPreparedStatement implements Call
* @throws SQLException if this object is closed or invalid
*/
public int executeUpdate() throws SQLException {
if (command.isQuery()) {
super.executeQuery().next();
return 0;
try {
checkClosed();
if (command.isQuery()) {
super.executeQuery().next();
return 0;
}
return super.executeUpdate();
} catch (Exception e) {
throw logAndConvert(e);
}
return super.executeUpdate();
}
/**
* Registers the given OUT parameter.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @param sqlType the data type (Types.x) - ignored
*/
public void registerOutParameter(int parameterIndex, int sqlType) throws SQLException {
registerOutParameter(parameterIndex, sqlType, 0);
}
public void registerOutParameter(int parameterIndex, int sqlType, int scale) throws SQLException {
registerOutParameter(parameterIndex, sqlType, scale, null);
registerOutParameter(parameterIndex);
}
private ResultSetMetaData getCheckedMetaData() throws SQLException {
ResultSetMetaData meta = getMetaData();
if (meta == null) {
throw DbException.getUnsupportedException("Supported only for stored procedures calling.");
}
return meta;
/**
* Registers the given OUT parameter.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @param sqlType the data type (Types.x) - ignored
* @param typeName the SQL type name - ignored
*/
public void registerOutParameter(int parameterIndex, int sqlType, String typeName) throws SQLException {
registerOutParameter(parameterIndex);
}
private void checkIndexBounds(int parameterIndex) throws SQLException {
if (parameterIndex < 1 || parameterIndex > maxOutParameters) {
throw DbException.getInvalidValueException(Integer.toString(parameterIndex), "parameterIndex");
}
/**
* Registers the given OUT parameter.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @param sqlType the data type (Types.x)
* @param scale is ignored
*/
public void registerOutParameter(int parameterIndex, int sqlType, int scale) throws SQLException {
registerOutParameter(parameterIndex);
}
private void registerOutParameter(int parameterIndex, int sqlType, int scale, String typeName) throws SQLException {
try {
if (outParameters == null) {
maxOutParameters = Math.min(getParameterMetaData().getParameterCount(), getCheckedMetaData()
.getColumnCount());
outParameters = new BitField();
}
checkIndexBounds(parameterIndex);
ParameterInterface param = command.getParameters().get(--parameterIndex);
if (param.getParamValue() == null) {
param.setValue(ValueNull.INSTANCE, false);
}
outParameters.set(parameterIndex);
} catch (Exception e) {
throw logAndConvert(e);
}
/**
* Registers the given OUT parameter.
*
* @param parameterName the parameter name
* @param sqlType the data type (Types.x) - ignored
* @param typeName the SQL type name - ignored
*/
public void registerOutParameter(String parameterName, int sqlType, String typeName) throws SQLException {
registerOutParameter(getIndexForName(parameterName), sqlType, typeName);
}
private void checkRegistered(int parameterIndex) throws SQLException {
try {
checkIndexBounds(parameterIndex);
if (!outParameters.get(parameterIndex - 1)) {
throw DbException.getInvalidValueException(Integer.toString(parameterIndex), "parameterIndex");
}
} catch (Exception e) {
throw logAndConvert(e);
}
/**
* Registers the given OUT parameter.
*
* @param parameterName the parameter name
* @param sqlType the data type (Types.x) - ignored
* @param scale is ignored
*/
public void registerOutParameter(String parameterName, int sqlType, int scale) throws SQLException {
registerOutParameter(getIndexForName(parameterName), sqlType, scale);
}
private int getIndexForName(String parameterName) throws SQLException {
try {
if (namedParameters == null) {
ResultSetMetaData meta = getCheckedMetaData();
int columnCount = meta.getColumnCount();
Map<String, Integer> map = new HashMap<String, Integer>(columnCount);
for (int i = 1; i <= columnCount; i++) {
map.put(meta.getColumnLabel(i), i);
}
namedParameters = map;
}
Integer index = namedParameters.get(parameterName);
if (index == null) {
throw DbException.getInvalidValueException(parameterName, "parameterName");
}
return index;
} catch (Exception e) {
throw logAndConvert(e);
}
/**
* Registers the given OUT parameter.
*
* @param parameterName the parameter name
* @param sqlType the data type (Types.x) - ignored
*/
public void registerOutParameter(String parameterName, int sqlType) throws SQLException {
registerOutParameter(getIndexForName(parameterName), sqlType);
}
/**
* Returns whether the last column accessed was null.
*
* @return true if the last column accessed was null
*/
public boolean wasNull() throws SQLException {
if (resultSet == null) {
throw logAndConvert(DbException
.getUnsupportedException("Method wasNull() should be called only after statement execution and calling a getter method."));
}
return resultSet.wasNull();
return getOpenResultSet().wasNull();
}
/**
* [Not supported]
*/
public URL getURL(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return resultSet.getURL(parameterIndex);
throw unsupported("url");
}
/**
* Returns the value of the specified column as a String.
*
* @param parameterIndex (1,2,...)
* @return the value
* @throws SQLException if the column is not found or if the result set is closed
*/
public String getString(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return resultSet.getString(parameterIndex);
return getOpenResultSet().getString(parameterIndex);
}
/**
* Returns the value of the specified column as a boolean.
*
* @param parameterIndex (1,2,...)
* @return the value
* @throws SQLException if the column is not found or if the result set is
* closed
*/
public boolean getBoolean(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return resultSet.getBoolean(parameterIndex);
return getOpenResultSet().getBoolean(parameterIndex);
}
/**
* Returns the value of the specified column as a byte.
*
* @param parameterIndex (1,2,...)
* @return the value
* @throws SQLException if the column is not found or if the result set is
* closed
*/
public byte getByte(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return resultSet.getByte(parameterIndex);
return getOpenResultSet().getByte(parameterIndex);
}
/**
* Returns the value of the specified column as a short.
*
* @param parameterIndex (1,2,...)
* @return the value
* @throws SQLException if the column is not found or if the result set is
* closed
*/
public short getShort(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return resultSet.getShort(parameterIndex);
return getOpenResultSet().getShort(parameterIndex);
}
/**
* Returns the value of the specified column as an int.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @return the value
* @throws SQLException if the column is not found or if the result set is closed
*/
public int getInt(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return resultSet.getInt(parameterIndex);
return getOpenResultSet().getInt(parameterIndex);
}
/**
* Returns the value of the specified column as a long.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @return the value
* @throws SQLException if the column is not found or if the result set is
* closed
*/
public long getLong(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return resultSet.getLong(parameterIndex);
return getOpenResultSet().getLong(parameterIndex);
}
/**
* Returns the value of the specified column as a float.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @return the value
* @throws SQLException if the column is not found or if the result set is
* closed
*/
public float getFloat(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return resultSet.getFloat(parameterIndex);
return getOpenResultSet().getFloat(parameterIndex);
}
/**
* Returns the value of the specified column as a double.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @return the value
* @throws SQLException if the column is not found or if the result set is
* closed
*/
public double getDouble(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return resultSet.getDouble(parameterIndex);
return getOpenResultSet().getDouble(parameterIndex);
}
/**
* @see java.sql.CallableStatement#getBigDecimal(int, int)
* @deprecated use <code>getBigDecimal(int parameterIndex)</code>
* or <code>getBigDecimal(String parameterName)</code>
* Returns the value of the specified column as a BigDecimal.
*
* @deprecated
*
* @param parameterIndex the parameter index (1, 2, ...)
* @return the value
* @throws SQLException if the column is not found or if the result set is
* closed
*/
public BigDecimal getBigDecimal(int parameterIndex, int scale) throws SQLException {
checkRegistered(parameterIndex);
return resultSet.getBigDecimal(parameterIndex, scale);
return getOpenResultSet().getBigDecimal(parameterIndex, scale);
}
/**
* Returns the value of the specified column as a byte array.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @return the value
* @throws SQLException if the column is not found or if the result set is
* closed
*/
public byte[] getBytes(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return resultSet.getBytes(parameterIndex);
return getOpenResultSet().getBytes(parameterIndex);
}
/**
* Returns the value of the specified column as a java.sql.Date.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @return the value
* @throws SQLException if the column is not found or if the result set is closed
*/
public Date getDate(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return resultSet.getDate(parameterIndex);
return getOpenResultSet().getDate(parameterIndex);
}
/**
* Returns the value of the specified column as a java.sql.Time.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @return the value
* @throws SQLException if the column is not found or if the result set is closed
*/
public Time getTime(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return resultSet.getTime(parameterIndex);
return getOpenResultSet().getTime(parameterIndex);
}
/**
* Returns the value of the specified column as a java.sql.Timestamp.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @return the value
* @throws SQLException if the column is not found or if the result set is closed
*/
public Timestamp getTimestamp(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return resultSet.getTimestamp(parameterIndex);
return getOpenResultSet().getTimestamp(parameterIndex);
}
/**
* Returns a column value as a Java object. The data is
* de-serialized into a Java object (on the client side).
*
* @param parameterIndex the parameter index (1, 2, ...)
* @return the value or null
* @throws SQLException if the column is not found or if the result set is
* closed
*/
public Object getObject(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return resultSet.getObject(parameterIndex);
return getOpenResultSet().getObject(parameterIndex);
}
/**
* Returns the value of the specified column as a BigDecimal.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @return the value
* @throws SQLException if the column is not found or if the result set is closed
*/
public BigDecimal getBigDecimal(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return resultSet.getBigDecimal(parameterIndex);
return getOpenResultSet().getBigDecimal(parameterIndex);
}
/**
* [Not supported] Gets a column as a object using the specified type
* mapping.
*/
public Object getObject(int parameterIndex, Map<String, Class<?>> map) throws SQLException {
checkRegistered(parameterIndex);
return resultSet.getObject(parameterIndex, map);
throw unsupported("map");
}
/**
* [Not supported] Gets a column as a reference.
*/
public Ref getRef(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return resultSet.getRef(parameterIndex);
throw unsupported("ref");
}
/**
* Returns the value of the specified column as a Blob.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @return the value
* @throws SQLException if the column is not found or if the result set is
* closed
*/
public Blob getBlob(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return resultSet.getBlob(parameterIndex);
return getOpenResultSet().getBlob(parameterIndex);
}
/**
* Returns the value of the specified column as a Clob.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @return the value
* @throws SQLException if the column is not found or if the result set is
* closed
*/
public Clob getClob(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return resultSet.getClob(parameterIndex);
return getOpenResultSet().getClob(parameterIndex);
}
/**
* Returns the value of the specified column as an Array.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @return the value
* @throws SQLException if the column is not found or if the result set is
* closed
*/
public Array getArray(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return resultSet.getArray(parameterIndex);
return getOpenResultSet().getArray(parameterIndex);
}
/**
* Returns the value of the specified column as a java.sql.Date using a
* specified time zone.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @param calendar the calendar
* @return the value
* @throws SQLException if the column is not found or if the result set is
* closed
*/
public Date getDate(int parameterIndex, Calendar cal) throws SQLException {
checkRegistered(parameterIndex);
return resultSet.getDate(parameterIndex, cal);
return getOpenResultSet().getDate(parameterIndex, cal);
}
/**
* Returns the value of the specified column as a java.sql.Time using a
* specified time zone.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @param calendar the calendar
* @return the value
* @throws SQLException if the column is not found or if the result set is
* closed
*/
public Time getTime(int parameterIndex, Calendar cal) throws SQLException {
checkRegistered(parameterIndex);
return resultSet.getTime(parameterIndex, cal);
return getOpenResultSet().getTime(parameterIndex, cal);
}
/**
* Returns the value of the specified column as a java.sql.Timestamp using a
* specified time zone.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @param calendar the calendar
* @return the value
* @throws SQLException if the column is not found or if the result set is
* closed
*/
public Timestamp getTimestamp(int parameterIndex, Calendar cal) throws SQLException {
checkRegistered(parameterIndex);
return resultSet.getTimestamp(parameterIndex, cal);
}
public void registerOutParameter(int parameterIndex, int sqlType, String typeName) throws SQLException {
registerOutParameter(parameterIndex, sqlType, 0, typeName);
return getOpenResultSet().getTimestamp(parameterIndex, cal);
}
/**
* [Not supported]
*/
public URL getURL(String parameterName) throws SQLException {
return getURL(getIndexForName(parameterName));
throw unsupported("url");
}
/**
* Returns the value of the specified column as a java.sql.Timestamp using a
* specified time zone.
*
* @param parameterName the parameter name
* @param calendar the calendar
* @return the value
* @throws SQLException if the column is not found or if the result set is
* closed
*/
public Timestamp getTimestamp(String parameterName, Calendar cal) throws SQLException {
return getTimestamp(getIndexForName(parameterName), cal);
}
/**
* Returns the value of the specified column as a java.sql.Time using a
* specified time zone.
*
* @param parameterName the parameter name
* @param calendar the calendar
* @return the value
* @throws SQLException if the column is not found or if the result set is
* closed
*/
public Time getTime(String parameterName, Calendar cal) throws SQLException {
return getTime(getIndexForName(parameterName), cal);
}
/**
* Returns the value of the specified column as a java.sql.Date using a
* specified time zone.
*
* @param parameterName the parameter name
* @param calendar the calendar
* @return the value
* @throws SQLException if the column is not found or if the result set is closed
*/
public Date getDate(String parameterName, Calendar cal) throws SQLException {
return getDate(getIndexForName(parameterName), cal);
}
/**
* Returns the value of the specified column as an Array.
*
* @param parameterName the parameter name
* @return the value
* @throws SQLException if the column is not found or if the result set is
* closed
*/
public Array getArray(String parameterName) throws SQLException {
return getArray(getIndexForName(parameterName));
}
/**
* Returns the value of the specified column as a Clob.
*
* @param parameterName the parameter name
* @return the value
* @throws SQLException if the column is not found or if the result set is
* closed
*/
public Clob getClob(String parameterName) throws SQLException {
return getClob(getIndexForName(parameterName));
}
/**
* Returns the value of the specified column as a Blob.
*
* @param parameterName the parameter name
* @return the value
* @throws SQLException if the column is not found or if the result set is
* closed
*/
public Blob getBlob(String parameterName) throws SQLException {
return getBlob(getIndexForName(parameterName));
}
/**
* [Not supported] Gets a column as a reference.
*/
public Ref getRef(String parameterName) throws SQLException {
return getRef(getIndexForName(parameterName));
throw unsupported("ref");
}
/**
* [Not supported] Gets a column as a object using the specified type
* mapping.
*/
public Object getObject(String parameterName, Map<String, Class<?>> map) throws SQLException {
return getObject(getIndexForName(parameterName), map);
throw unsupported("map");
}
/**
* Returns the value of the specified column as a BigDecimal.
*
* @param parameterName the parameter name
* @return the value
* @throws SQLException if the column is not found or if the result set is
* closed
*/
public BigDecimal getBigDecimal(String parameterName) throws SQLException {
return getBigDecimal(getIndexForName(parameterName));
}
/**
* Returns a column value as a Java object. The data is
* de-serialized into a Java object (on the client side).
*
* @param parameterName the parameter name
* @return the value or null
* @throws SQLException if the column is not found or if the result set is
* closed
*/
public Object getObject(String parameterName) throws SQLException {
return getObject(getIndexForName(parameterName));
}
/**
* Returns the value of the specified column as a java.sql.Timestamp.
*
* @param parameterName the parameter name
* @return the value
* @throws SQLException if the column is not found or if the result set is
* closed
*/
public Timestamp getTimestamp(String parameterName) throws SQLException {
return getTimestamp(getIndexForName(parameterName));
}
/**
* Returns the value of the specified column as a java.sql.Time.
*
* @param parameterName the parameter name
* @return the value
* @throws SQLException if the column is not found or if the result set is
* closed
*/
public Time getTime(String parameterName) throws SQLException {
return getTime(getIndexForName(parameterName));
}
/**
* Returns the value of the specified column as a java.sql.Date.
*
* @param parameterName the parameter name
* @return the value
* @throws SQLException if the column is not found or if the result set is closed
*/
public Date getDate(String parameterName) throws SQLException {
return getDate(getIndexForName(parameterName));
}
/**
* Returns the value of the specified column as a byte array.
*
* @param parameterName the parameter name
* @return the value
* @throws SQLException if the column is not found or if the result set is
* closed
*/
public byte[] getBytes(String parameterName) throws SQLException {
return getBytes(getIndexForName(parameterName));
}
/**
* Returns the value of the specified column as a double.
*
* @param parameterName the parameter name
* @return the value
* @throws SQLException if the column is not found or if the result set is
* closed
*/
public double getDouble(String parameterName) throws SQLException {
return getDouble(getIndexForName(parameterName));
}
/**
* Returns the value of the specified column as a float.
*
* @param parameterName the parameter name
* @return the value
* @throws SQLException if the column is not found or if the result set is
* closed
*/
public float getFloat(String parameterName) throws SQLException {
return getFloat(getIndexForName(parameterName));
}
/**
* Returns the value of the specified column as a long.
*
* @param parameterName the parameter name
* @return the value
* @throws SQLException if the column is not found or if the result set is
* closed
*/
public long getLong(String parameterName) throws SQLException {
return getLong(getIndexForName(parameterName));
}
/**
* Returns the value of the specified column as an int.
*
* @param parameterName the parameter name
* @return the value
* @throws SQLException if the column is not found or if the result set is closed
*/
public int getInt(String parameterName) throws SQLException {
return getInt(getIndexForName(parameterName));
}
/**
* Returns the value of the specified column as a short.
*
* @param parameterName the parameter name
* @return the value
* @throws SQLException if the column is not found or if the result set is
* closed
*/
public short getShort(String parameterName) throws SQLException {
return getShort(getIndexForName(parameterName));
}
/**
* Returns the value of the specified column as a byte.
*
* @param parameterName the parameter name
* @return the value
* @throws SQLException if the column is not found or if the result set is
* closed
*/
public byte getByte(String parameterName) throws SQLException {
return getByte(getIndexForName(parameterName));
}
/**
* Returns the value of the specified column as a boolean.
*
* @param parameterName the parameter name
* @return the value
* @throws SQLException if the column is not found or if the result set is
* closed
*/
public boolean getBoolean(String parameterName) throws SQLException {
return getBoolean(getIndexForName(parameterName));
}
/**
* Returns the value of the specified column as a String.
*
* @param parameterName the parameter name
* @return the value
* @throws SQLException if the column is not found or if the result set is closed
*/
public String getString(String parameterName) throws SQLException {
return getString(getIndexForName(parameterName));
}
// --- setters --------------------------------------------------
public void setNull(String parameterName, int sqlType, String typeName) throws SQLException {
setNull(getIndexForName(parameterName), sqlType, typeName);
}
public void setTimestamp(String parameterName, Timestamp x, Calendar cal) throws SQLException {
setTimestamp(getIndexForName(parameterName), x, cal);
/**
* [Not supported] Returns the value of the specified column as a row id.
*
* @param parameterIndex the parameter index (1, 2, ...)
*/
//## Java 1.6 begin ##
public RowId getRowId(int parameterIndex) throws SQLException {
throw unsupported("rowId");
}
//## Java 1.6 end ##
public void setTime(String parameterName, Time x, Calendar cal) throws SQLException {
setTime(getIndexForName(parameterName), x, cal);
/**
* [Not supported] Returns the value of the specified column as a row id.
*
* @param parameterName the parameter name
*/
//## Java 1.6 begin ##
public RowId getRowId(String parameterName) throws SQLException {
throw unsupported("rowId");
}
//## Java 1.6 end ##
public void setDate(String parameterName, Date x, Calendar cal) throws SQLException {
setDate(getIndexForName(parameterName), x, cal);
/**
* Returns the value of the specified column as a Clob.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @return the value
* @throws SQLException if the column is not found or if the result set is closed
*/
//## Java 1.6 begin ##
public NClob getNClob(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return getOpenResultSet().getNClob(parameterIndex);
}
//## Java 1.6 end ##
public void setCharacterStream(String parameterName, Reader reader, int length) throws SQLException {
setCharacterStream(getIndexForName(parameterName), reader, length);
/**
* Returns the value of the specified column as a Clob.
*
* @param parameterName the parameter name
* @return the value
* @throws SQLException if the column is not found or if the result set is closed
*/
//## Java 1.6 begin ##
public NClob getNClob(String parameterName) throws SQLException {
return getNClob(getIndexForName(parameterName));
}
//## Java 1.6 end ##
/**
* [Not supported] Returns the value of the specified column as a SQLXML object.
*/
//## Java 1.6 begin ##
public SQLXML getSQLXML(int parameterIndex) throws SQLException {
throw unsupported("SQLXML");
}
//## Java 1.6 end ##
/**
* [Not supported] Returns the value of the specified column as a SQLXML object.
*/
//## Java 1.6 begin ##
public SQLXML getSQLXML(String parameterName) throws SQLException {
throw unsupported("SQLXML");
}
//## Java 1.6 end ##
/**
* Returns the value of the specified column as a String.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @return the value
* @throws SQLException if the column is not found or if the result set is
* closed
*/
//## Java 1.6 begin ##
public String getNString(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return getOpenResultSet().getNString(parameterIndex);
}
//## Java 1.6 end ##
/**
* Returns the value of the specified column as a String.
*
* @param parameterName the parameter name
* @return the value
* @throws SQLException if the column is not found or if the result set is
* closed
*/
//## Java 1.6 begin ##
public String getNString(String parameterName) throws SQLException {
return getNString(getIndexForName(parameterName));
}
//## Java 1.6 end ##
/**
* Returns the value of the specified column as a reader.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @return the value
* @throws SQLException if the column is not found or if the result set is
* closed
*/
//## Java 1.6 begin ##
public Reader getNCharacterStream(int parameterIndex)
throws SQLException {
checkRegistered(parameterIndex);
return getOpenResultSet().getNCharacterStream(parameterIndex);
}
//## Java 1.6 end ##
/**
* Returns the value of the specified column as a reader.
*
* @param parameterName the parameter name
* @return the value
* @throws SQLException if the column is not found or if the result set is
* closed
*/
//## Java 1.6 begin ##
public Reader getNCharacterStream(String parameterName)
throws SQLException {
return getNCharacterStream(getIndexForName(parameterName));
}
//## Java 1.6 end ##
/**
* Returns the value of the specified column as a reader.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @return the value
* @throws SQLException if the column is not found or if the result set is
* closed
*/
//## Java 1.6 begin ##
public Reader getCharacterStream(int parameterIndex)
throws SQLException {
checkRegistered(parameterIndex);
return getOpenResultSet().getCharacterStream(parameterIndex);
}
//## Java 1.6 end ##
/**
* Returns the value of the specified column as a reader.
*
* @param parameterName the parameter name
* @return the value
* @throws SQLException if the column is not found or if the result set is
* closed
*/
//## Java 1.6 begin ##
public Reader getCharacterStream(String parameterName)
throws SQLException {
return getCharacterStream(getIndexForName(parameterName));
}
//## Java 1.6 end ##
// =============================================================
/**
* Sets a parameter to null.
*
* @param parameterName the parameter name
* @param sqlType the data type (Types.x)
* @param typeName this parameter is ignored
* @throws SQLException if this object is closed
*/
public void setNull(String parameterName, int sqlType, String typeName) throws SQLException {
setNull(getIndexForName(parameterName), sqlType, typeName);
}
/**
* Sets a parameter to null.
*
* @param parameterName the parameter name
* @param sqlType the data type (Types.x)
* @throws SQLException if this object is closed
*/
public void setNull(String parameterName, int sqlType) throws SQLException {
setNull(getIndexForName(parameterName), sqlType);
}
/**
* Sets the timestamp using a specified time zone. The value will be
* converted to the local time zone.
*
* @param parameterName the parameter name
* @param x the value
* @param calendar the calendar
* @throws SQLException if this object is closed
*/
public void setTimestamp(String parameterName, Timestamp x, Calendar cal) throws SQLException {
setTimestamp(getIndexForName(parameterName), x, cal);
}
/**
* Sets the time using a specified time zone. The value will be converted to
* the local time zone.
*
* @param parameterName the parameter name
* @param x the value
* @param calendar the calendar
* @throws SQLException if this object is closed
*/
public void setTime(String parameterName, Time x, Calendar cal) throws SQLException {
setTime(getIndexForName(parameterName), x, cal);
}
/**
* Sets the date using a specified time zone. The value will be converted to
* the local time zone.
*
* @param parameterName the parameter name
* @param x the value
* @param calendar the calendar
* @throws SQLException if this object is closed
*/
public void setDate(String parameterName, Date x, Calendar cal) throws SQLException {
setDate(getIndexForName(parameterName), x, cal);
}
/**
* Sets the value of a parameter as a character stream.
* This method does not close the reader.
* The reader may be closed after executing the statement.
*
* @param parameterName the parameter name
* @param x the value
* @param length the number of bytes
* @throws SQLException if this object is closed
*/
public void setCharacterStream(String parameterName, Reader reader, int length) throws SQLException {
setCharacterStream(getIndexForName(parameterName), reader, length);
}
/**
* Sets the value of a parameter.
* Objects of unknown classes are serialized (on the client side).
*
* @param parameterName the parameter name
* @param x the value
* @throws SQLException if this object is closed
*/
public void setObject(String parameterName, Object x) throws SQLException {
setObject(getIndexForName(parameterName), x);
}
/**
* Sets the value of a parameter. The object is converted, if required, to
* the specified data type before sending to the database.
* Objects of unknown classes are serialized (on the client side).
*
* @param parameterName the parameter name
* @param x the value, null is allowed
* @param targetSqlType the type as defined in java.sql.Types
* @throws SQLException if this object is closed
*/
public void setObject(String parameterName, Object x, int targetSqlType) throws SQLException {
setObject(getIndexForName(parameterName), x, targetSqlType);
}
/**
* Sets the value of a parameter. The object is converted, if required, to
* the specified data type before sending to the database.
* Objects of unknown classes are serialized (on the client side).
*
* @param parameterName the parameter name
* @param x the value, null is allowed
* @param targetSqlType the type as defined in java.sql.Types
* @param scale is ignored
* @throws SQLException if this object is closed
*/
public void setObject(String parameterName, Object x, int targetSqlType, int scale) throws SQLException {
setObject(getIndexForName(parameterName), x, targetSqlType, scale);
}
/**
* Sets the value of a parameter as an input stream.
* This method does not close the stream.
* The stream may be closed after executing the statement.
*
* @param parameterName the parameter name
* @param x the value
* @param length the number of bytes
* @throws SQLException if this object is closed
*/
public void setBinaryStream(String parameterName, InputStream x, int length) throws SQLException {
setBinaryStream(getIndexForName(parameterName), x, length);
}
//## Java 1.6 begin ##
/**
* Sets the value of a parameter as an ASCII stream.
* This method does not close the stream.
* The stream may be closed after executing the statement.
*
* @param parameterName the parameter name
* @param x the value
* @param length the number of bytes
* @throws SQLException if this object is closed
*/
public void setAsciiStream(String parameterName,
InputStream x, long length) throws SQLException {
setAsciiStream(getIndexForName(parameterName), x, length);
}
//## Java 1.6 end ##
/**
* Sets the value of a parameter.
*
* @param parameterName the parameter name
* @param x the value
* @throws SQLException if this object is closed
*/
public void setTimestamp(String parameterName, Timestamp x) throws SQLException {
setTimestamp(getIndexForName(parameterName), x);
}
/**
* Sets the time using a specified time zone. The value will be converted to
* the local time zone.
*
* @param parameterName the parameter name
* @param x the value
* @param calendar the calendar
* @throws SQLException if this object is closed
*/
public void setTime(String parameterName, Time x) throws SQLException {
setTime(getIndexForName(parameterName), x);
}
/**
* Sets the value of a parameter.
*
* @param parameterName the parameter name
* @param x the value
* @throws SQLException if this object is closed
*/
public void setDate(String parameterName, Date x) throws SQLException {
setDate(getIndexForName(parameterName), x);
}
/**
* Sets the value of a parameter as a byte array.
*
* @param parameterName the parameter name
* @param x the value
* @throws SQLException if this object is closed
*/
public void setBytes(String parameterName, byte[] x) throws SQLException {
setBytes(getIndexForName(parameterName), x);
}
/**
* Sets the value of a parameter.
*
* @param parameterName the parameter name
* @param x the value
* @throws SQLException if this object is closed
*/
public void setString(String parameterName, String x) throws SQLException {
setString(getIndexForName(parameterName), x);
}
/**
* Sets the value of a parameter.
*
* @param parameterName the parameter name
* @param x the value
* @throws SQLException if this object is closed
*/
public void setBigDecimal(String parameterName, BigDecimal x) throws SQLException {
setBigDecimal(getIndexForName(parameterName), x);
}
/**
* Sets the value of a parameter.
*
* @param parameterName the parameter name
* @param x the value
* @throws SQLException if this object is closed
*/
public void setDouble(String parameterName, double x) throws SQLException {
setDouble(getIndexForName(parameterName), x);
}
/**
* Sets the value of a parameter.
*
* @param parameterName the parameter name
* @param x the value
* @throws SQLException if this object is closed
*/
public void setFloat(String parameterName, float x) throws SQLException {
setFloat(getIndexForName(parameterName), x);
}
/**
* Sets the value of a parameter.
*
* @param parameterName the parameter name
* @param x the value
* @throws SQLException if this object is closed
*/
public void setLong(String parameterName, long x) throws SQLException {
setLong(getIndexForName(parameterName), x);
}
/**
* Sets the value of a parameter.
*
* @param parameterName the parameter name
* @param x the value
* @throws SQLException if this object is closed
*/
public void setInt(String parameterName, int x) throws SQLException {
setInt(getIndexForName(parameterName), x);
}
/**
* Sets the value of a parameter.
*
* @param parameterName the parameter name
* @param x the value
* @throws SQLException if this object is closed
*/
public void setShort(String parameterName, short x) throws SQLException {
setShort(getIndexForName(parameterName), x);
}
/**
* Sets the value of a parameter.
*
* @param parameterName the parameter name
* @param x the value
* @throws SQLException if this object is closed
*/
public void setByte(String parameterName, byte x) throws SQLException {
setByte(getIndexForName(parameterName), x);
}
/**
* Sets the value of a parameter.
*
* @param parameterName the parameter name
* @param x the value
* @throws SQLException if this object is closed
*/
public void setBoolean(String parameterName, boolean x) throws SQLException {
setBoolean(getIndexForName(parameterName), x);
}
public void setNull(String parameterName, int sqlType) throws SQLException {
setNull(getIndexForName(parameterName), sqlType);
}
/**
* [Not supported]
*/
public void setURL(String parameterName, URL val) throws SQLException {
setURL(getIndexForName(parameterName), val);
}
// --- other methods --------------------------------------------
public void registerOutParameter(String parameterName, int sqlType, String typeName) throws SQLException {
registerOutParameter(getIndexForName(parameterName), sqlType, typeName);
}
public void registerOutParameter(String parameterName, int sqlType, int scale) throws SQLException {
registerOutParameter(getIndexForName(parameterName), sqlType, scale);
}
public void registerOutParameter(String parameterName, int sqlType) throws SQLException {
registerOutParameter(getIndexForName(parameterName), sqlType);
}
// =============================================================
//## Java 1.6 begin ##
public RowId getRowId(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return resultSet.getRowId(parameterIndex);
throw unsupported("url");
}
//## Java 1.6 end ##
//## Java 1.6 begin ##
public RowId getRowId(String parameterName) throws SQLException {
return getRowId(getIndexForName(parameterName));
}
//## Java 1.6 end ##
/**
* [Not supported] Sets the value of a parameter as a row id.
*/
//## Java 1.6 begin ##
public void setRowId(String parameterName, RowId x)
throws SQLException {
setRowId(getIndexForName(parameterName), x);
throw unsupported("rowId");
}
//## Java 1.6 end ##
/**
* Sets the value of a parameter.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @param x the value
* @throws SQLException if this object is closed
*/
//## Java 1.6 begin ##
public void setNString(String parameterName, String x)
throws SQLException {
......@@ -524,6 +1200,16 @@ public class JdbcCallableStatement extends JdbcPreparedStatement implements Call
}
//## Java 1.6 end ##
/**
* Sets the value of a parameter as a character stream.
* This method does not close the reader.
* The reader may be closed after executing the statement.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @param x the value
* @param length the number of bytes
* @throws SQLException if this object is closed
*/
//## Java 1.6 begin ##
public void setNCharacterStream(String parameterName,
Reader value, long length) throws SQLException {
......@@ -531,6 +1217,13 @@ public class JdbcCallableStatement extends JdbcPreparedStatement implements Call
}
//## Java 1.6 end ##
/**
* Sets the value of a parameter as a Clob.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @param x the value
* @throws SQLException if this object is closed
*/
//## Java 1.6 begin ##
public void setNClob(String parameterName, NClob value)
throws SQLException {
......@@ -538,6 +1231,15 @@ public class JdbcCallableStatement extends JdbcPreparedStatement implements Call
}
//## Java 1.6 end ##
/**
* Sets the value of a parameter as a Clob.
* This method does not close the reader.
* The reader may be closed after executing the statement.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @param x the value
* @throws SQLException if this object is closed
*/
//## Java 1.6 begin ##
public void setClob(String parameterName, Reader reader,
long length) throws SQLException {
......@@ -545,6 +1247,15 @@ public class JdbcCallableStatement extends JdbcPreparedStatement implements Call
}
//## Java 1.6 end ##
/**
* Sets the value of a parameter as a Blob.
* This method does not close the stream.
* The stream may be closed after executing the statement.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @param x the value
* @throws SQLException if this object is closed
*/
//## Java 1.6 begin ##
public void setBlob(String parameterName, InputStream inputStream,
long length) throws SQLException {
......@@ -552,6 +1263,15 @@ public class JdbcCallableStatement extends JdbcPreparedStatement implements Call
}
//## Java 1.6 end ##
/**
* Sets the value of a parameter as a Clob.
* This method does not close the reader.
* The reader may be closed after executing the statement.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @param x the value
* @throws SQLException if this object is closed
*/
//## Java 1.6 begin ##
public void setNClob(String parameterName, Reader reader,
long length) throws SQLException {
......@@ -559,82 +1279,13 @@ public class JdbcCallableStatement extends JdbcPreparedStatement implements Call
}
//## Java 1.6 end ##
//## Java 1.6 begin ##
public NClob getNClob(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return resultSet.getNClob(parameterIndex);
}
//## Java 1.6 end ##
//## Java 1.6 begin ##
public NClob getNClob(String parameterName) throws SQLException {
return getNClob(getIndexForName(parameterName));
}
//## Java 1.6 end ##
//## Java 1.6 begin ##
public void setSQLXML(String parameterName,
SQLXML xmlObject) throws SQLException {
setSQLXML(getIndexForName(parameterName), xmlObject);
}
//## Java 1.6 end ##
//## Java 1.6 begin ##
public SQLXML getSQLXML(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return resultSet.getSQLXML(parameterIndex);
}
//## Java 1.6 end ##
//## Java 1.6 begin ##
public SQLXML getSQLXML(String parameterName) throws SQLException {
return getSQLXML(getIndexForName(parameterName));
}
//## Java 1.6 end ##
//## Java 1.6 begin ##
public String getNString(int parameterIndex) throws SQLException {
checkRegistered(parameterIndex);
return resultSet.getNString(parameterIndex);
}
//## Java 1.6 end ##
//## Java 1.6 begin ##
public String getNString(String parameterName) throws SQLException {
return getNString(getIndexForName(parameterName));
}
//## Java 1.6 end ##
//## Java 1.6 begin ##
public Reader getNCharacterStream(int parameterIndex)
throws SQLException {
checkRegistered(parameterIndex);
return resultSet.getNCharacterStream(parameterIndex);
}
//## Java 1.6 end ##
//## Java 1.6 begin ##
public Reader getNCharacterStream(String parameterName)
throws SQLException {
return getNCharacterStream(getIndexForName(parameterName));
}
//## Java 1.6 end ##
//## Java 1.6 begin ##
public Reader getCharacterStream(int parameterIndex)
throws SQLException {
checkRegistered(parameterIndex);
return resultSet.getCharacterStream(parameterIndex);
}
//## Java 1.6 end ##
//## Java 1.6 begin ##
public Reader getCharacterStream(String parameterName)
throws SQLException {
return getCharacterStream(getIndexForName(parameterName));
}
//## Java 1.6 end ##
/**
* Sets the value of a parameter as a Blob.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @param x the value
* @throws SQLException if this object is closed
*/
//## Java 1.6 begin ##
public void setBlob(String parameterName, Blob x)
throws SQLException {
......@@ -642,12 +1293,28 @@ public class JdbcCallableStatement extends JdbcPreparedStatement implements Call
}
//## Java 1.6 end ##
/**
* Sets the value of a parameter as a Clob.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @param x the value
* @throws SQLException if this object is closed
*/
//## Java 1.6 begin ##
public void setClob(String parameterName, Clob x) throws SQLException {
setClob(getIndexForName(parameterName), x);
}
//## Java 1.6 end ##
/**
* Sets the value of a parameter as an ASCII stream.
* This method does not close the stream.
* The stream may be closed after executing the statement.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @param x the value
* @throws SQLException if this object is closed
*/
//## Java 1.6 begin ##
public void setAsciiStream(String parameterName, InputStream x)
throws SQLException {
......@@ -655,11 +1322,30 @@ public class JdbcCallableStatement extends JdbcPreparedStatement implements Call
}
//## Java 1.6 end ##
/**
* Sets the value of a parameter as an ASCII stream.
* This method does not close the stream.
* The stream may be closed after executing the statement.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @param x the value
* @param length the number of bytes
* @throws SQLException if this object is closed
*/
public void setAsciiStream(String parameterName,
InputStream x, int length) throws SQLException {
setAsciiStream(getIndexForName(parameterName), x, length);
}
/**
* Sets the value of a parameter as an input stream.
* This method does not close the stream.
* The stream may be closed after executing the statement.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @param x the value
* @throws SQLException if this object is closed
*/
//## Java 1.6 begin ##
public void setBinaryStream(String parameterName,
InputStream x) throws SQLException {
......@@ -667,6 +1353,16 @@ public class JdbcCallableStatement extends JdbcPreparedStatement implements Call
}
//## Java 1.6 end ##
/**
* Sets the value of a parameter as an input stream.
* This method does not close the stream.
* The stream may be closed after executing the statement.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @param x the value
* @param length the number of bytes
* @throws SQLException if this object is closed
*/
//## Java 1.6 begin ##
public void setBinaryStream(String parameterName,
InputStream x, long length) throws SQLException {
......@@ -674,6 +1370,15 @@ public class JdbcCallableStatement extends JdbcPreparedStatement implements Call
}
//## Java 1.6 end ##
/**
* Sets the value of a parameter as a Blob.
* This method does not close the stream.
* The stream may be closed after executing the statement.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @param x the value
* @throws SQLException if this object is closed
*/
//## Java 1.6 begin ##
public void setBlob(String parameterName, InputStream x)
throws SQLException {
......@@ -681,6 +1386,15 @@ public class JdbcCallableStatement extends JdbcPreparedStatement implements Call
}
//## Java 1.6 end ##
/**
* Sets the value of a parameter as a character stream.
* This method does not close the reader.
* The reader may be closed after executing the statement.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @param x the value
* @throws SQLException if this object is closed
*/
//## Java 1.6 begin ##
public void setCharacterStream(String parameterName, Reader x)
throws SQLException {
......@@ -688,6 +1402,16 @@ public class JdbcCallableStatement extends JdbcPreparedStatement implements Call
}
//## Java 1.6 end ##
/**
* Sets the value of a parameter as a character stream.
* This method does not close the reader.
* The reader may be closed after executing the statement.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @param x the value
* @param length the number of characters
* @throws SQLException if this object is closed
*/
//## Java 1.6 begin ##
public void setCharacterStream(String parameterName,
Reader x, long length) throws SQLException {
......@@ -695,12 +1419,30 @@ public class JdbcCallableStatement extends JdbcPreparedStatement implements Call
}
//## Java 1.6 end ##
/**
* Sets the value of a parameter as a character stream.
* This method does not close the reader.
* The reader may be closed after executing the statement.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @param x the value
* @throws SQLException if this object is closed
*/
//## Java 1.6 begin ##
public void setClob(String parameterName, Reader x) throws SQLException {
setClob(getIndexForName(parameterName), x);
}
//## Java 1.6 end ##
/**
* Sets the value of a parameter as a character stream.
* This method does not close the reader.
* The reader may be closed after executing the statement.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @param x the value
* @throws SQLException if this object is closed
*/
//## Java 1.6 begin ##
public void setNCharacterStream(String parameterName,
Reader x) throws SQLException {
......@@ -708,10 +1450,110 @@ public class JdbcCallableStatement extends JdbcPreparedStatement implements Call
}
//## Java 1.6 end ##
/**
* Sets the value of a parameter as a Clob.
* This method does not close the reader.
* The reader may be closed after executing the statement.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @param x the value
* @param length the number of characters
* @throws SQLException if this object is closed
*/
//## Java 1.6 begin ##
public void setNClob(String parameterName, Reader x) throws SQLException {
setNClob(getIndexForName(parameterName), x);
}
//## Java 1.6 end ##
/**
* [Not supported] Sets the value of a parameter as a SQLXML object.
*/
//## Java 1.6 begin ##
public void setSQLXML(String parameterName,
SQLXML xmlObject) throws SQLException {
throw unsupported("SQLXML");
}
//## Java 1.6 end ##
private ResultSetMetaData getCheckedMetaData() throws SQLException {
ResultSetMetaData meta = getMetaData();
if (meta == null) {
throw DbException.getUnsupportedException("Supported only for calling stored procedures");
}
return meta;
}
private void checkIndexBounds(int parameterIndex) throws SQLException {
checkClosed();
if (parameterIndex < 1 || parameterIndex > maxOutParameters) {
throw DbException.getInvalidValueException("" + parameterIndex, "parameterIndex");
}
}
private void registerOutParameter(int parameterIndex) throws SQLException {
try {
checkClosed();
if (outParameters == null) {
maxOutParameters = Math.min(
getParameterMetaData().getParameterCount(),
getCheckedMetaData().getColumnCount());
outParameters = new BitField();
}
checkIndexBounds(parameterIndex);
ParameterInterface param = command.getParameters().get(--parameterIndex);
if (param.getParamValue() == null) {
param.setValue(ValueNull.INSTANCE, false);
}
outParameters.set(parameterIndex);
} catch (Exception e) {
throw logAndConvert(e);
}
}
private void checkRegistered(int parameterIndex) throws SQLException {
try {
checkIndexBounds(parameterIndex);
if (!outParameters.get(parameterIndex - 1)) {
throw DbException.getInvalidValueException("" + parameterIndex, "parameterIndex");
}
} catch (Exception e) {
throw logAndConvert(e);
}
}
private int getIndexForName(String parameterName) throws SQLException {
try {
checkClosed();
if (namedParameters == null) {
ResultSetMetaData meta = getCheckedMetaData();
int columnCount = meta.getColumnCount();
HashMap<String, Integer> map = New.hashMap(columnCount);
for (int i = 1; i <= columnCount; i++) {
map.put(meta.getColumnLabel(i), i);
}
namedParameters = map;
}
Integer index = namedParameters.get(parameterName);
if (index == null) {
throw DbException.getInvalidValueException(parameterName, "parameterName");
}
return index;
} catch (Exception e) {
throw logAndConvert(e);
}
}
private JdbcResultSet getOpenResultSet() throws SQLException {
try {
checkClosed();
if (resultSet == null) {
throw DbException.get(ErrorCode.NO_DATA_AVAILABLE);
}
return resultSet;
} catch (Exception e) {
throw logAndConvert(e);
}
}
}
......@@ -945,7 +945,7 @@ public class JdbcPreparedStatement extends JdbcStatement implements PreparedStat
*
* @param parameterIndex the parameter index (1, 2, ...)
* @param x the value
* @param length the number of bytes
* @param length the number of characters
* @throws SQLException if this object is closed
*/
public void setCharacterStream(int parameterIndex, Reader x, int length) throws SQLException {
......@@ -972,7 +972,7 @@ public class JdbcPreparedStatement extends JdbcStatement implements PreparedStat
*
* @param parameterIndex the parameter index (1, 2, ...)
* @param x the value
* @param length the number of bytes
* @param length the number of characters
* @throws SQLException if this object is closed
*/
public void setCharacterStream(int parameterIndex, Reader x, long length) throws SQLException {
......@@ -1300,7 +1300,7 @@ public class JdbcPreparedStatement extends JdbcStatement implements PreparedStat
*
* @param parameterIndex the parameter index (1, 2, ...)
* @param x the value
* @param length the number of bytes
* @param length the number of characters
* @throws SQLException if this object is closed
*/
//## Java 1.6 begin ##
......@@ -1402,6 +1402,7 @@ public class JdbcPreparedStatement extends JdbcStatement implements PreparedStat
*
* @param parameterIndex the parameter index (1, 2, ...)
* @param x the value
* @param length the number of characters
* @throws SQLException if this object is closed
*/
public void setClob(int parameterIndex, Reader x, long length) throws SQLException {
......@@ -1454,6 +1455,7 @@ public class JdbcPreparedStatement extends JdbcStatement implements PreparedStat
*
* @param parameterIndex the parameter index (1, 2, ...)
* @param x the value
* @param length the number of characters
* @throws SQLException if this object is closed
*/
//## Java 1.6 begin ##
......
......@@ -319,7 +319,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
}
/**
* Returns the value of the specified column as a String.
* Returns the value of the specified column as a BigDecimal.
*
* @param columnIndex (1,2,...)
* @return the value
......@@ -383,11 +383,12 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
}
/**
* Returns the value of the specified column as a String.
* Returns the value of the specified column as a BigDecimal.
*
* @param columnLabel the column label
* @return the value
* @throws SQLException if the column is not found or if the result set is closed
* @throws SQLException if the column is not found or if the result set is
* closed
*/
public BigDecimal getBigDecimal(String columnLabel) throws SQLException {
try {
......@@ -419,7 +420,8 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
*
* @param columnLabel the column label
* @return the value
* @throws SQLException if the column is not found or if the result set is closed
* @throws SQLException if the column is not found or if the result set is
* closed
*/
public Time getTime(String columnLabel) throws SQLException {
try {
......@@ -435,7 +437,8 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
*
* @param columnLabel the column label
* @return the value
* @throws SQLException if the column is not found or if the result set is closed
* @throws SQLException if the column is not found or if the result set is
* closed
*/
public Timestamp getTimestamp(String columnLabel) throws SQLException {
try {
......@@ -691,7 +694,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
}
/**
* Returns the value of the specified column as a String.
* Returns the value of the specified column as a BigDecimal.
*
* @deprecated
*
......@@ -716,7 +719,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
}
/**
* Returns the value of the specified column as a String.
* Returns the value of the specified column as a BigDecimal.
*
* @deprecated
*
......@@ -760,7 +763,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
* [Not supported] Gets a column as a object using the specified type
* mapping.
*/
public Object getObject(int columnIndex, Map<String, Class< ? >> map) throws SQLException {
public Object getObject(int columnIndex, Map<String, Class<?>> map) throws SQLException {
throw unsupported("map");
}
......@@ -990,7 +993,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
}
/**
* Returns the value of the specified column as input stream.
* Returns the value of the specified column as an input stream.
*
* @param columnIndex (1,2,...)
* @return the value
......@@ -1007,7 +1010,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
}
/**
* Returns the value of the specified column as input stream.
* Returns the value of the specified column as an input stream.
*
* @param columnLabel the column label
* @return the value
......@@ -1101,7 +1104,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
}
/**
* Returns the value of the specified column as input stream.
* Returns the value of the specified column as an input stream.
*
* @param columnIndex (1,2,...)
* @return the value
......@@ -1119,7 +1122,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
}
/**
* Returns the value of the specified column as input stream.
* Returns the value of the specified column as an input stream.
*
* @param columnLabel the column label
* @return the value
......@@ -1137,7 +1140,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
}
/**
* Returns the value of the specified column as input stream.
* Returns the value of the specified column as a reader.
*
* @param columnIndex (1,2,...)
* @return the value
......@@ -1154,7 +1157,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
}
/**
* Returns the value of the specified column as input stream.
* Returns the value of the specified column as a reader.
*
* @param columnLabel the column label
* @return the value
......@@ -3286,7 +3289,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
//## Java 1.6 end ##
/**
* Returns the value of the specified column as input stream.
* Returns the value of the specified column as a reader.
*
* @param columnIndex (1,2,...)
* @return the value
......@@ -3305,7 +3308,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
//## Java 1.6 end ##
/**
* Returns the value of the specified column as input stream.
* Returns the value of the specified column as a reader.
*
* @param columnLabel the column label
* @return the value
......
......@@ -14,6 +14,7 @@ import java.sql.Statement;
import java.sql.Timestamp;
import java.sql.Types;
import org.h2.constant.ErrorCode;
import org.h2.test.TestBase;
import org.h2.tools.SimpleResultSet;
......@@ -98,6 +99,23 @@ public class TestCallableStatement extends TestBase {
} catch (SQLException e) {
// expected exception
}
// test for exceptions after closing
call.close();
try {
call.executeUpdate();
} catch (SQLException e) {
assertEquals(ErrorCode.OBJECT_CLOSED, e.getErrorCode());
}
try {
call.registerOutParameter(1, Types.INTEGER);
} catch (SQLException e) {
assertEquals(ErrorCode.OBJECT_CLOSED, e.getErrorCode());
}
try {
call.getURL("X");
} catch (SQLException e) {
assertEquals(ErrorCode.OBJECT_CLOSED, e.getErrorCode());
}
}
/**
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论