|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Sybase extensions to the PreparedStatement
interface.
PreparedStatement
,
Connection.prepareStatement(java.lang.String)
Method Summary | |
void |
setBigDecimal(int parameterIndex,
BigDecimal x,
int precision,
int scale)
The NUMERIC datatype for Sybase has explicit declarations for the precision (total number of digits) and scale (digits after the decimal). |
Methods inherited from interface java.sql.PreparedStatement |
addBatch,
clearParameters,
execute,
executeQuery,
executeUpdate,
getMetaData,
setArray,
setAsciiStream,
setBigDecimal,
setBinaryStream,
setBlob,
setBoolean,
setByte,
setBytes,
setCharacterStream,
setClob,
setDate,
setDate,
setDouble,
setFloat,
setInt,
setLong,
setNull,
setNull,
setObject,
setObject,
setObject,
setRef,
setShort,
setString,
setTime,
setTime,
setTimestamp,
setTimestamp,
setUnicodeStream |
Methods inherited from interface com.sybase.jdbcx.SybStatement |
getConnection,
getFetchSize,
getResultSetConcurrency,
getSybMessageHandler,
setCursorName,
setFetchSize,
setSybMessageHandler |
Method Detail |
public void setBigDecimal(int parameterIndex, BigDecimal x, int precision, int scale) throws SQLException
Unfortunately, if the parameter is being used for an in/out stored procedure parameter the guess really matters and we often guess wrong. Suppose the stored procedure is declared as follows:
CREATE PROCEDURE myNumericProc(@p1 NUMERIC(6,0) OUTPUT) AS BEGIN SELECT @p1 = @p1 * 10 END
If the input value is BigDecimal("1") jConnect will send a NUMERIC(1,0). This results in a numeric overflow when the server returns 10 - doesn't fit.
OTOH, if we just decide to send the value as NUMERIC(38,0) - the maximum precision, or any other precision > 6, the server will raise an error because our precision is too high for the stored procedure declaration.
The only way to correct this would be to query the server on the declared precision/scale of stored procedure parameters, but that would require jConnect to have a much more complete SQL parser so it could determine name/order of stored procedure and parameter name, and would incur a significant performance overhead for additional round-trips to the database to gather this information.
This alternate signature setBigDecimal extension allows a jConnect JDBC application to explicitly indicate what NUMERIC precision and scale should be used.
parameterIndex
- index of the parameter being set.x
- value being sentprecision
- the maximum number of digits in the value of xscale
- the maximum number of digits to the right of the decimal
in the value of x.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |