The ParameterMetaData
interface in JDBC provides insights into the parameters of a PreparedStatement
. It reveals information about placeholders in precompiled SQL statements, such as expected data types and properties. This metadata aids developers in debugging, ensuring data type consistency, and dynamically constructing SQL queries. Additionally, it’s valuable for tools interfacing with databases to offer enhanced user experiences and error checks.
getParameterCount
Retrieves the number of parameters in the PreparedStatement
object for which this ParameterMetaData
object contains information.
Signature:
int getParameterCount() throws SQLException
Returns:
Return Type | Description |
---|---|
int | The number of parameters in the PreparedStatement . |
isNullable
Indicates the nullability status of the specified parameter.
Signature:
int isNullable( int param ) throws SQLException
Parameters:
Parameter Name | Type | Description |
---|---|---|
param | int | The index of the parameter to check. |
Returns:
Return Type | Description |
---|---|
int | The nullability status, which can be one of ParameterMetaData.parameterNoNulls , ParameterMetaData.parameterNullable , or ParameterMetaData.parameterNullableUnknown . |
isSigned
Determines if the specified parameter can have a negative value.
Signature:
boolean isSigned(int param) throws SQLException
Parameters:
Parameter Name | Type | Description |
---|---|---|
param | int | The index of the parameter to check. |
Returns:
Return Type | Description |
---|---|
boolean | true if the parameter can be signed (negative); false otherwise. |
getPrecision
Retrieves the specified precision (number of decimal digits) for the given parameter.
Signature:
int getPrecision( int param ) throws SQLException
Parameters:
Parameter Name | Type | Description |
---|---|---|
param | int | The index of the parameter to check. |
Returns:
Return Type | Description |
---|---|
int | The precision of the column. 0 means unknown precision. |
getScale
Fetches the scale (number of digits to the right of the decimal point) of the specified parameter.
Signature:
int getScale( int param ) throws SQLException
Parameters:
Parameter Name | Type | Description |
---|---|---|
param | int | The index of the parameter to check. |
Returns:
Return Type | Description |
---|---|
int | The scale of the parameter. 0 means unknown scale. |
getParameterType
Returns the SQL type for the given parameter.
Signature:
int getParameterType( int param ) throws SQLException
Parameters:
Parameter Name | Type | Description |
---|---|---|
param | int | The index of the parameter to check. |
Returns:
Return Type | Description |
---|---|
int | The SQL type, as defined in java.sql.Types . |
getParameterTypeName
Returns the database-specific type name of the specified parameter.
Signature:
String getParameterTypeName( int param ) throws SQLException
Parameters:
Parameter Name | Type | Description |
---|---|---|
param | int | The index of the parameter whose type name to retrieve. |
Returns:
Return Type | Description |
---|---|
String | The database-specific type name of the parameter. |
getParameterClassName
Provides the fully-qualified name of the Java class which the specified parameter will be converted to when retrieved from the ResultSet
.
Signature:
String getParameterClassName( int param ) throws SQLException
Parameters:
Parameter Name | Type | Description |
---|---|---|
param | int | The index of the parameter whose class name to retrieve. |
Returns:
Return Type | Description |
---|---|
String | The fully-qualified name of the Java class. |
getParameterMode
Indicates the mode of the parameter. This can be IN
, OUT
, or INOUT
.
Signature:
int getParameterMode( int param ) throws SQLException
Parameters:
Parameter Name | Type | Description |
---|---|---|
param | int | The index of the parameter to check. |
Returns:
Return Type | Description |
---|---|
int | The mode of the parameter, one of ParameterMetaData.parameterModeIn , ParameterMetaData.parameterModeOut , or ParameterMetaData.parameterModeInOut . |
unwrap
Returns an object that implements the given interface to allow access to vendor-specific methods.
Signature:
<T> T unwrap( Class<T> aClass ) throws SQLException
Parameters:
Parameter Name | Type | Description |
---|---|---|
aClass | Class<T> |
The type of the object to return. |
Returns:
Return Type | Description |
---|---|
T | An object that implements the given interface. |
isWrapperFor
Determines whether this object is a wrapper for an object with the specified interface.
Signature:
boolean isWrapperFor( Class<?> aClass ) throws SQLException
Parameters:
Parameter Name | Type | Description |
---|---|---|
aClass | Class<?> |
The interface to check against. |
Returns:
Return Type | Description |
---|---|
boolean | true if this object implements the interface or directly/indirectly wraps an object that does; false otherwise. |