📄 preparedstatement_base.java
字号:
if (execute())
{
startResultSet();
closeResults();
throw new SQLException("executeUpdate can't return a result set");
}
else
{
return getUpdateCount();
}
}
/**
* When a very large ASCII value is input to a LONGVARCHAR
* parameter, it may be more practical to send it via a
* java.io.InputStream. JDBC will read the data from the stream
* as needed, until it reaches end-of-file. The JDBC driver will
* do any necessary conversion from ASCII to the database char format.
*
* <P><B>Note:</B> This stream object can either be a standard
* Java stream object or your own subclass that implements the
* standard interface.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x the java input stream which contains the ASCII parameter value
* @param length the number of bytes in the stream
* @exception SQLException if a database-access error occurs.
*/
public void setAsciiStream(int parameterIndex,
java.io.InputStream x,
int length)
throws SQLException
{
//NotImplemented();
if (length == 0) {
setParam(parameterIndex, " ", 12, 1);
}
else {
byte[] b = new byte[length];
try {
int i = x.read(b);
} catch (IOException ioe) {
}
setParam(parameterIndex, new String(b), 12, length);
}
}
/**
* Set a parameter to a java.lang.BigDecimal value.
* The driver converts this to a SQL NUMERIC value when
* it sends it to the database.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x the parameter value
* @exception SQLException if a database-access error occurs.
*/
public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException
{
//NotImplemented();
setParam(parameterIndex, new Float(x.floatValue()), 7, -1);
}
/**
* When a very large binary value is input to a LONGVARBINARY
* parameter, it may be more practical to send it via a
* java.io.InputStream. JDBC will read the data from the stream
* as needed, until it reaches end-of-file.
*
* <P><B>Note:</B> This stream object can either be a standard
* Java stream object or your own subclass that implements the
* standard interface.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x the java input stream which contains the binary parameter value
* @param length the number of bytes in the stream
* @exception SQLException if a database-access error occurs.
*/
public void setBinaryStream(int parameterIndex,
java.io.InputStream x,
int length)
throws SQLException
{
//NotImplemented();
byte[] b = new byte[length];
try {
int i = x.read(b);
} catch (IOException io) {
}
if (b == null || length <= 255) {
setParam(parameterIndex, b, -3, -1);
}
else {
setParam(parameterIndex, b, -4, -1);
}
}
/**
* Set a parameter to a Java boolean value. The driver converts this
* to a SQL BIT value when it sends it to the database.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x the parameter value
* @exception SQLException if a database-access error occurs.
*/
public void setBoolean(int parameterIndex, boolean x) throws SQLException
{
byte[] b = new byte[1];
if(x==true) {
b[0] = 1;
//setParam(parameterIndex, b, -7, -1); }
setParam(parameterIndex, new Byte("1"), -7, -1); }
else {
b[0] = 0;
//setParam(parameterIndex, b, -7, -1);
setParam(parameterIndex, new Byte("0"), -7, -1);
}
}
/**
* Set a parameter to a Java byte value. The driver converts this
* to a SQL TINYINT value when it sends it to the database.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x the parameter value
* @exception SQLException if a database-access error occurs.
*/
public void setByte(int index, byte x) throws SQLException
{
//throw new SQLException("Not implemented");
byte[] b = new byte[1];
b[0] = x;
setParam(index, b, -3, -1);
}
/**
* Set a parameter to a Java array of bytes. The driver converts
* this to a SQL VARBINARY or LONGVARBINARY (depending on the
* argument's size relative to the driver's limits on VARBINARYs)
* when it sends it to the database.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x the parameter value
* @exception SQLException if a database-access error occurs.
*/
public void setBytes(int parameterIndex, byte x[]) throws SQLException
{
// when this method creates the parameter the formal type should
// be a varbinary if the length of 'x' is <=255, image if length>255.
if (x == null || x.length<=255)
{
setParam(parameterIndex, x, java.sql.Types.VARBINARY, -1);
}
else
{
setParam(parameterIndex, x, java.sql.Types.LONGVARBINARY, -1);
}
}
/**
* Set a parameter to a java.sql.Date value. The driver converts this
* to a SQL DATE value when it sends it to the database.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x the parameter value
* @exception SQLException if a database-access error occurs.
*/
public void setDate(int parameterIndex, java.sql.Date value)
throws SQLException
{
setParam(parameterIndex,
//new java.util.Date(value.getYear(), value.getMonth(), value.getDate()),
new java.sql.Date(value.getYear(), value.getMonth(), value.getDate()),
java.sql.Types.DATE,
-1);
}
/**
* Set a parameter to a Java double value. The driver converts this
* to a SQL DOUBLE value when it sends it to the database.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x the parameter value
* @exception SQLException if a database-access error occurs.
*/
public void setDouble(int parameterIndex, double value) throws SQLException
{
setParam(parameterIndex, new Double(value), java.sql.Types.DOUBLE, -1);
}
/**
* Set a parameter to a Java float value. The driver converts this
* to a SQL FLOAT value when it sends it to the database.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x the parameter value
* @exception SQLException if a database-access error occurs.
*/
public void setFloat(int parameterIndex, float value) throws SQLException
{
setParam(parameterIndex, new Float(value), java.sql.Types.REAL, -1);
}
/**
* Set a parameter to a Java int value. The driver converts this
* to a SQL INTEGER value when it sends it to the database.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x the parameter value
* @exception SQLException if a database-access error occurs.
*/
public void setInt(int index, int value) throws SQLException
{
setParam(index, new Integer(value), java.sql.Types.INTEGER, -1);
}
/**
* Set a parameter to a Java long value. The driver converts this
* to a SQL BIGINT value when it sends it to the database.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x the parameter value
* @exception SQLException if a database-access error occurs.
*/
public void setLong(int parameterIndex, long value) throws SQLException
{
setParam(parameterIndex, new Long(value), java.sql.Types.BIGINT, -1);
}
/**
* Set a parameter to SQL NULL.
*
* <P><B>Note:</B> You must specify the parameter's SQL type.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param sqlType SQL type code defined by java.sql.Types
* @exception SQLException if a database-access error occurs.
*/
public void setNull(int index, int type) throws SQLException
{
setParam(index, null, type, -1);
}
/**
* <p>Set the value of a parameter using an object; use the
* java.lang equivalent objects for integral values.
*
* <p>The JDBC specification specifies a standard mapping from
* Java Object types to SQL types. The given argument java object
* will be converted to the corresponding SQL type before being
* sent to the database.
*
* <p>Note that this method may be used to pass datatabase
* specific abstract data types, by using a Driver specific Java
* type.
*
* @param parameterIndex The first parameter is 1, the second is 2, ...
* @param x The object containing the input parameter value
* @exception SQLException if a database-access error occurs.
*/
public void setObject(int parameterIndex, Object x) throws SQLException
{
//throw new SQLException("Not implemented");
String xname = x.getClass().getName();
if (xname.equalsIgnoreCase("java.math.BigDecimal")) {
BigDecimal b = new BigDecimal(x.toString());
Float f = new Float(b.floatValue());
setParam(parameterIndex, new Float(b.floatValue()), 7, -1);
}
else if (xname.equalsIgnoreCase("java.lang.Boolean")) {
int[] i = new int[1];
Boolean b = new Boolean(x.toString());
if (b.equals("true")) {
i[0] = 1;
setParam(parameterIndex, i, -7, -1);
}
else {
i[0] = 1;
setParam(parameterIndex, i, -7, -1);
}
}
else if (xname.equalsIgnoreCase("java.lang.Byte")) {
Byte by = new Byte(x.toString());
byte[] b = new byte[1];
b[0] = by.byteValue();
setParam(parameterIndex, b, -3, -1);
}
else if (xname.equalsIgnoreCase("java.sql.Date")) {
Date d = Date.valueOf(x.toString());
setParam(parameterIndex, new Date(d.getYear(), d.getMonth(), d.getDate()),
91, -1);
}
else if (xname.equalsIgnoreCase("java.lang.Double")) {
setParam(parameterIndex, new Double(x.toString()), 8, -1);
}
else if (xname.equalsIgnoreCase("java.lang.Float")) {
setParam(parameterIndex, new Float(x.toString()), 6, -1);
}
else if (xname.equalsIgnoreCase("java.lang.Integer")) {
setParam(parameterIndex, new Integer(x.toString()), 4, -1);
}
else if (xname.equalsIgnoreCase("java.lang.Long")) {
setParam(parameterIndex, new Long(x.toString()), -5, -1);
}
else if (xname.equalsIgnoreCase("java.lang.Short")) {
setParam(parameterIndex, new Integer(x.toString()), 5, -1);
}
else if (xname.equalsIgnoreCase("java.lang.String")) {
setParam(parameterIndex, x.toString(), 12, x.toString().length());
}
else if (xname.equalsIgnoreCase("java.sql.Time")) {
Time t = Time.valueOf(x.toString());
setParam(parameterIndex, t, 92, -1);
}
else if (xname.equalsIgnoreCase("java.sql.Timestamp")) {
Timestamp ts = Timestamp.valueOf(x.toString());
setParam(parameterIndex, ts, 93, -1);
}
else {
throw new SQLException("No validate Object type1.");
}
}
/**
* This method is like setObject above, but assumes a scale of zero.
*
* @exception SQLException if a database-access error occurs.
*/
public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException
{
//throw new SQLException("Not implemented");
if (targetSqlType == 7) {
BigDecimal b = new BigDecimal(x.toString());
Float f = new Float(b.floatValue());
setParam(parameterIndex, new Float(b.floatValue()), 7, -1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -