📄 jtdspreparedstatement.java
字号:
}
}
}
public void setBinaryStream(int parameterIndex, InputStream x, int length)
throws SQLException {
checkOpen();
if (x == null || length < 0) {
setBytes(parameterIndex, null);
} else {
setParameter(parameterIndex, x, java.sql.Types.LONGVARBINARY, 0, length);
}
}
public void setUnicodeStream(int parameterIndex, InputStream inputStream, int length)
throws SQLException {
checkOpen();
if (inputStream == null || length < 0) {
setString(parameterIndex, null);
} else {
try {
length /= 2;
char[] tmp = new char[length];
int pos = 0;
int b1 = inputStream.read();
int b2 = inputStream.read();
while (b1 >= 0 && b2 >= 0 && pos < length) {
tmp[pos++] = (char) (((b1 << 8) &0xFF00) | (b2 & 0xFF));
b1 = inputStream.read();
b2 = inputStream.read();
}
setString(parameterIndex, new String(tmp, 0, pos));
} catch (java.io.IOException e) {
throw new SQLException(Messages.get("error.generic.ioerror",
e.getMessage()), "HY000");
}
}
}
public void setCharacterStream(int parameterIndex, Reader reader, int length)
throws SQLException {
if (reader == null || length < 0) {
setParameter(parameterIndex, null, java.sql.Types.LONGVARCHAR, 0, 0);
} else {
setParameter(parameterIndex, reader, java.sql.Types.LONGVARCHAR, 0, length);
}
}
public void setObject(int parameterIndex, Object x) throws SQLException {
setObjectBase(parameterIndex, x, Support.getJdbcType(x), -1);
}
public void setObject(int parameterIndex, Object x, int targetSqlType)
throws SQLException {
setObjectBase(parameterIndex, x, targetSqlType, -1);
}
public void setObject(int parameterIndex, Object x, int targetSqlType, int scale)
throws SQLException {
checkOpen();
if (scale < 0 || scale > connection.getMaxPrecision()) {
throw new SQLException(Messages.get("error.generic.badscale"), "HY092");
}
setObjectBase(parameterIndex, x, targetSqlType, scale);
}
public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException {
notImplemented("PreparedStatement.setNull(int, int, String)");
}
public void setString(int parameterIndex, String x) throws SQLException {
setParameter(parameterIndex, x, java.sql.Types.VARCHAR, 0, 0);
}
public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException {
setParameter(parameterIndex, x, java.sql.Types.DECIMAL, -1, 0);
}
public void setURL(int parameterIndex, URL url) throws SQLException {
setString(parameterIndex, (url == null)? null: url.toString());
}
public void setArray(int arg0, Array arg1) throws SQLException {
notImplemented("PreparedStatement.setArray");
}
public void setBlob(int parameterIndex, Blob x) throws SQLException {
if (x == null) {
setBytes(parameterIndex, null);
} else {
long length = x.length();
if (length > Integer.MAX_VALUE) {
throw new SQLException(Messages.get("error.resultset.longblob"), "24000");
}
setBinaryStream(parameterIndex, x.getBinaryStream(), (int) x.length());
}
}
public void setClob(int parameterIndex, Clob x) throws SQLException {
if (x == null) {
this.setString(parameterIndex, null);
} else {
long length = x.length();
if (length > Integer.MAX_VALUE) {
throw new SQLException(Messages.get("error.resultset.longclob"), "24000");
}
setCharacterStream(parameterIndex, x.getCharacterStream(), (int) x.length());
}
}
public void setDate(int parameterIndex, Date x) throws SQLException {
setParameter(parameterIndex, x, java.sql.Types.DATE, 0, 0);
}
public ParameterMetaData getParameterMetaData() throws SQLException {
checkOpen();
//
// NB. This is usable only with the JDBC3 version of the interface.
//
if (connection.getServerType() == Driver.SYBASE) {
// Sybase does return the parameter types for prepared sql.
connection.prepareSQL(this, sql, new ParamInfo[0], false, false);
}
try {
Class pmdClass = Class.forName("net.sourceforge.jtds.jdbc.ParameterMetaDataImpl");
Class[] parameterTypes = new Class[] {ParamInfo[].class, ConnectionJDBC2.class};
Object[] arguments = new Object[] {parameters, connection};
Constructor pmdConstructor = pmdClass.getConstructor(parameterTypes);
return (ParameterMetaData) pmdConstructor.newInstance(arguments);
} catch (Exception e) {
notImplemented("PreparedStatement.getParameterMetaData");
}
return null;
}
public void setRef(int parameterIndex, Ref x) throws SQLException {
notImplemented("PreparedStatement.setRef");
}
public ResultSet executeQuery() throws SQLException {
checkOpen();
initialize();
boolean useCursor = useCursor(false, null);
if (procName == null && !(this instanceof JtdsCallableStatement)) {
// Sync on the connection to make sure rollback() isn't called
// between the moment when the statement is prepared and the moment
// when it's executed.
synchronized (connection) {
String spName = connection.prepareSQL(this, sql, parameters, false, useCursor);
return executeSQLQuery(sql, spName, parameters, useCursor);
}
} else {
return executeSQLQuery(sql, procName, parameters, useCursor);
}
}
public ResultSetMetaData getMetaData() throws SQLException {
checkOpen();
if (colMetaData == null) {
if (currentResult != null) {
colMetaData = currentResult.columns;
} else if (connection.getServerType() == Driver.SYBASE) {
// Sybase can provide meta data as a by product of preparing the call.
connection.prepareSQL(this, sql, new ParamInfo[0], false, false);
if (colMetaData == null) {
return null; // Sorry still no go
}
} else {
// For Microsoft set all parameters to null and execute the query.
// SET FMTONLY ON asks the server just to return meta data.
// This only works for select statements
if (!"select".equals(sqlWord)) {
return null;
}
// Copy parameters to avoid corrupting any values already set
// by the user as we need to set a flag and null out the data.
ParamInfo[] params = new ParamInfo[parameters.length];
for (int i = 0; i < params.length; i++) {
params[i] = new ParamInfo(parameters[i].markerPos, false);
params[i].isSet = true;
}
// Substitute nulls into SQL String
StringBuffer testSql = new StringBuffer(sql.length() + 128);
testSql.append("SET FMTONLY ON ");
testSql.append(
Support.substituteParameters(sql, params, connection));
testSql.append(" SET FMTONLY OFF");
try {
tds.submitSQL(testSql.toString());
colMetaData = tds.getColumns();
} catch (SQLException e) {
// Ensure FMTONLY is switched off!
tds.submitSQL("SET FMTONLY OFF");
return null;
}
}
}
return new JtdsResultSetMetaData(colMetaData,
JtdsResultSet.getColumnCount(colMetaData),
connection.getUseLOBs());
}
public void setTime(int parameterIndex, Time x) throws SQLException {
setParameter( parameterIndex, x, java.sql.Types.TIME, 0, 0 );
}
public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException {
setParameter(parameterIndex, x, java.sql.Types.TIMESTAMP, 0, 0);
}
public void setDate(int parameterIndex, Date x, Calendar cal)
throws SQLException {
if (x != null && cal != null) {
x = new java.sql.Date(Support.timeFromZone(x, cal));
}
setDate(parameterIndex, x);
}
public void setTime(int parameterIndex, Time x, Calendar cal)
throws SQLException {
if (x != null && cal != null) {
x = new Time(Support.timeFromZone(x, cal));
}
setTime(parameterIndex, x);
}
public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal)
throws SQLException {
if (x != null && cal != null) {
x = new java.sql.Timestamp(Support.timeFromZone(x, cal));
}
setTimestamp(parameterIndex, x);
}
public int executeUpdate(String sql) throws SQLException {
notSupported("executeUpdate(String)");
return 0;
}
public void addBatch(String sql) throws SQLException {
notSupported("executeBatch(String)");
}
public boolean execute(String sql) throws SQLException {
notSupported("execute(String)");
return false;
}
public int executeUpdate(String sql, int getKeys) throws SQLException {
notSupported("executeUpdate(String, int)");
return 0;
}
public boolean execute(String arg0, int arg1) throws SQLException {
notSupported("execute(String, int)");
return false;
}
public int executeUpdate(String arg0, int[] arg1) throws SQLException {
notSupported("executeUpdate(String, int[])");
return 0;
}
public boolean execute(String arg0, int[] arg1) throws SQLException {
notSupported("execute(String, int[])");
return false;
}
public int executeUpdate(String arg0, String[] arg1) throws SQLException {
notSupported("executeUpdate(String, String[])");
return 0;
}
public boolean execute(String arg0, String[] arg1) throws SQLException {
notSupported("execute(String, String[])");
return false;
}
public ResultSet executeQuery(String sql) throws SQLException {
notSupported("executeQuery(String)");
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -