📄 jdbcpreparedstatement.java
字号:
*
* @param parameterIndex the parameter index (1, 2, ...)
* @param x the value
* @throws SQLException if this object is closed
*/
public void setBlob(int parameterIndex, InputStream x) throws SQLException {
try {
if (debug()) {
debugCode("setBlob("+parameterIndex+", x);");
}
checkClosed();
Value v = conn.createBlob(x, -1);
setParameter(parameterIndex, v);
} catch (Throwable e) {
throw logAndConvert(e);
}
}
/**
* 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
*/
public void setClob(int parameterIndex, Clob x) throws SQLException {
try {
if (debug()) {
debugCode("setClob("+parameterIndex+", x);");
}
checkClosed();
Value v;
if (x == null) {
v = ValueNull.INSTANCE;
} else {
v = conn.createClob(x.getCharacterStream(), -1);
}
setParameter(parameterIndex, v);
} catch (Throwable e) {
throw logAndConvert(e);
}
}
/**
* 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
*/
public void setClob(int parameterIndex, Reader x) throws SQLException {
try {
if (debug()) {
debugCode("setClob("+parameterIndex+", x);");
}
checkClosed();
Value v;
if (x == null) {
v = ValueNull.INSTANCE;
} else {
v = conn.createClob(x, -1);
}
setParameter(parameterIndex, v);
} catch (Throwable e) {
throw logAndConvert(e);
}
}
/**
* [Not supported] Sets the value of a parameter as a Array.
*/
public void setArray(int parameterIndex, Array x) throws SQLException {
try {
if (debug()) {
debugCode("setArray("+parameterIndex+", x);");
}
throw Message.getUnsupportedException();
} catch (Throwable e) {
throw logAndConvert(e);
}
}
/**
* Sets the value of a parameter as a byte array.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @param x the value
* @throws SQLException if this object is closed
*/
public void setBytes(int parameterIndex, byte[] x) throws SQLException {
try {
if (debug()) {
debugCode("setBytes("+parameterIndex+", "+quoteBytes(x)+");");
}
// TODO clone the byte array (each array! maybe other objects)
// by default (maybe use a setting?)
Value v = x == null ? (Value) ValueNull.INSTANCE : ValueBytes.get(x);
setParameter(parameterIndex, v);
} catch (Throwable e) {
throw logAndConvert(e);
}
}
/**
* Sets the value of a parameter as an input stream.
*
* @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 setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException {
try {
if (debug()) {
debugCode("setBinaryStream("+parameterIndex+", x, "+length+"L);");
}
checkClosed();
Value v = conn.createBlob(x, length);
setParameter(parameterIndex, v);
} catch (Throwable e) {
throw logAndConvert(e);
}
}
/**
* Sets the value of a parameter as an input stream.
*
* @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 setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException {
setBinaryStream(parameterIndex, x, (long) length);
}
/**
* Sets the value of a parameter as an input stream.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @param x the value
* @throws SQLException if this object is closed
*/
public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException {
setBinaryStream(parameterIndex, x, -1);
}
/**
* Sets the value of a parameter as an ASCII stream.
*
* @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(int parameterIndex, InputStream x, int length) throws SQLException {
setAsciiStream(parameterIndex, x, (long) length);
}
/**
* Sets the value of a parameter as an ASCII stream.
*
* @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(int parameterIndex, InputStream x, long length) throws SQLException {
try {
if (debug()) {
debugCode("setAsciiStream("+parameterIndex+", x, "+length+"L);");
}
checkClosed();
Value v = conn.createClob(IOUtils.getAsciiReader(x), length);
setParameter(parameterIndex, v);
} catch (Throwable e) {
throw logAndConvert(e);
}
}
/**
* Sets the value of a parameter as an ASCII stream.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @param x the value
* @throws SQLException if this object is closed
*/
public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException {
setAsciiStream(parameterIndex, x, -1);
}
/**
* Sets the value of a parameter as a character stream.
*
* @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 setCharacterStream(int parameterIndex, Reader x, int length) throws SQLException {
setCharacterStream(parameterIndex, x, (long) length);
}
/**
* Sets the value of a parameter as a character stream.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @param x the value
* @throws SQLException if this object is closed
*/
public void setCharacterStream(int parameterIndex, Reader x) throws SQLException {
setCharacterStream(parameterIndex, x, -1);
}
/**
* Sets the value of a parameter as a character stream.
*
* @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 setCharacterStream(int parameterIndex, Reader x, long length) throws SQLException {
try {
if (debug()) {
debugCode("setCharacterStream("+parameterIndex+", x, "+length+"L);");
}
checkClosed();
Value v = conn.createClob(x, length);
setParameter(parameterIndex, v);
} catch (Throwable e) {
throw logAndConvert(e);
}
}
/**
* [Not supported]
*/
public void setURL(int parameterIndex, URL x) throws SQLException {
try {
if (debug()) {
debugCode("setURL("+parameterIndex+", x);");
}
throw Message.getUnsupportedException();
} catch (Throwable e) {
throw logAndConvert(e);
}
}
/**
* Gets the result set metadata of the query returned when the statement is
* executed. If this is not a query, this method returns null.
*
* @return the meta data or null if this is not a query
* @throws SQLException if this object is closed
*/
public ResultSetMetaData getMetaData() throws SQLException {
try {
debugCodeCall("getMetaData");
checkClosed();
ResultInterface result = command.getMetaData();
if (result == null) {
return null;
}
int id = getNextId(TraceObject.RESULT_SET_META_DATA);
if (debug()) {
debugCodeAssign("ResultSetMetaData", TraceObject.RESULT_SET_META_DATA, id, "getMetaData()");
}
String catalog = conn.getCatalog();
JdbcResultSetMetaData meta = new JdbcResultSetMetaData(null, this, result, catalog, session.getTrace(), id);
return meta;
} catch (Throwable e) {
throw logAndConvert(e);
}
}
/**
* Clears the batch.
*/
public void clearBatch() throws SQLException {
try {
debugCodeCall("clearBatch");
checkClosed();
batchParameters = null;
} catch (Throwable e) {
throw logAndConvert(e);
}
}
/**
* Closes this statement.
* All result sets that where created by this statement
* become invalid after calling this method.
*/
public void close() throws SQLException {
try {
super.close();
if (command != null) {
command.close();
command = null;
}
} catch (Throwable e) {
throw logAndConvert(e);
}
}
/**
* Executes the batch.
*
* @return the array of update counts
*/
public int[] executeBatch() throws SQLException {
try {
debugCodeCall("executeBatch");
checkClosed();
if (batchParameters == null) {
// TODO batch: check what other database do if no parameters are set
batchParameters = new ObjectArray();
}
int[] result = new int[batchParameters.size()];
boolean error = false;
SQLException next = null;
for (int i = 0; i < batchParameters.size(); i++) {
ObjectArray parameters = command.getParameters();
Value[] set = (Value[]) batchParameters.get(i);
for (int j = 0; j < set.length; j++) {
Value value = set[j];
ParameterInterface param = (ParameterInterface) parameters.get(j);
param.setValue(value);
}
try {
result[i] = executeUpdateInternal();
} catch (SQLException e) {
if (next == null) {
next = e;
} else {
e.setNextException(next);
next = e;
}
logAndConvert(e);
//#ifdef JDK14
result[i] = Statement.EXECUTE_FAILED;
//#endif
error = true;
}
}
batchParameters = null;
if (error) {
JdbcBatchUpdateException e = new JdbcBatchUpdateException(next, result);
e.setNextException(next);
throw e;
}
return result;
} catch (Throwable e) {
throw logAndConvert(e);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -