use of java.sql.ParameterMetaData in project derby by apache.
the class VerifySignatures method collectClassesFromPreparedStatement.
/**
* Perform JDBC operations on a <code>PreparedStatement</code>.
* Collect the classes of all JDBC objects that are found.
*
* @param conn connection to a database
* @param classes set into which classes are collected
* @exception SQLException if a database error occurs
*/
private static void collectClassesFromPreparedStatement(Connection conn, Set<ClassInfo> classes) throws SQLException {
PreparedStatement ps = conn.prepareStatement("VALUES(1)");
addClass(classes, ps.getClass(), java.sql.PreparedStatement.class);
ResultSet rs = ps.executeQuery();
addClass(classes, rs.getClass(), java.sql.ResultSet.class);
rs.close();
ParameterMetaData pmd = ps.getParameterMetaData();
addClass(classes, pmd.getClass(), java.sql.ParameterMetaData.class);
ps.close();
}
use of java.sql.ParameterMetaData in project derby by apache.
the class ParameterMetaDataJdbc30Test method testCallableStatement.
/**
* Testing a callable statement by calling a SQL procedure with
* IN parameters, OUT parameters and IN_OUT parameters.
*
* @exception SQLException if error occurs
*/
public void testCallableStatement() throws SQLException {
Statement stmt = createStatement();
stmt.executeUpdate("create procedure dummyint( " + "in a integer, in b integer, " + "out c integer, inout d integer) " + "language java external name " + "'org.apache.derbyTesting.functionTests." + "tests.jdbcapi.ParameterMetaDataJdbc30Test.dummyint' " + "parameter style java");
CallableStatement cs = prepareCall("CALL dummyint(?,?,?,?)");
// parameters 1 and 2 are input only
cs.setInt(1, 1);
cs.setInt(2, 1);
// parameter 3 is output only
cs.registerOutParameter(3, Types.INTEGER);
// parameter 4 is input and output
Object x = 1;
cs.setObject(4, x, Types.INTEGER);
cs.registerOutParameter(4, Types.INTEGER);
// verify the meta data for the parameters
ParameterMetaData paramMetaData = cs.getParameterMetaData();
assertEquals("Unexpected parameter count", 4, paramMetaData.getParameterCount());
// expected values to be stored in a 2dim. array
String[][] parameterMetaDataArray0 = { // isNullable, isSigned, getPrecision, getScale, getParameterType, getParameterTypeName, getParameterClassName, getParameterMode
{ "PARAMETER_NULLABLE", "true", "10", "0", "4", "INTEGER", "java.lang.Integer", "PARAMETER_MODE_IN" }, { "PARAMETER_NULLABLE", "true", "10", "0", "4", "INTEGER", "java.lang.Integer", "PARAMETER_MODE_IN" }, { "PARAMETER_NULLABLE", "true", "10", "0", "4", "INTEGER", "java.lang.Integer", "PARAMETER_MODE_OUT" }, { "PARAMETER_NULLABLE", "true", "10", "0", "4", "INTEGER", "java.lang.Integer", "PARAMETER_MODE_IN_OUT" } };
testParameterMetaData(paramMetaData, parameterMetaDataArray0);
cs.execute();
/*
/* bug 4450 - parameter meta data info for the return parameter was giving
/* null pointer exception. In the past, we didn't need to keep the return
/* parameter info for callable statement execution and hence we never
/* generated the meta data for it. To fix the problem, at the parsing time,
/* I set a flag if the call statement is of ? = form. If so, the first
/* parameter is a return parameter and save it's meta data rather than
/* discarding it.
*/
cs = prepareCall("? = call RDB(?)");
paramMetaData = cs.getParameterMetaData();
assertEquals("Unexpected parameter count", 2, paramMetaData.getParameterCount());
// expected values to be stored in a 2dim. array
String[][] parameterMetaDataArray1 = { // isNullable, isSigned, getPrecision, getScale, getParameterType, getParameterTypeName, getParameterClassName, getParameterMode
{ "PARAMETER_NULLABLE", "true", "31", "0", "3", "DECIMAL", "java.math.BigDecimal", "PARAMETER_MODE_OUT" }, { "PARAMETER_NULLABLE", "true", "10", "0", "4", "INTEGER", "java.lang.Integer", "PARAMETER_MODE_IN" } };
testParameterMetaData(paramMetaData, parameterMetaDataArray1);
stmt.execute("drop procedure dummyint");
stmt.close();
cs.close();
}
use of java.sql.ParameterMetaData in project derby by apache.
the class ParameterMetaDataJdbc30Test method testParameterMetadataWithDECIMALParameters.
/**
* test ParameterMetaData for Java procedures with DECIMAL parameters
*
* @exception SQLException if error occurs
*/
public void testParameterMetadataWithDECIMALParameters() throws SQLException {
CallableStatement cs = prepareCall("CALL PMDD(?, ?, ?, ?)");
// parameters 1 and 2 are input only
cs.setBigDecimal(1, new BigDecimal("1"));
;
cs.setBigDecimal(2, new BigDecimal("1"));
;
// parameter 3 is input and output
Object x = new BigDecimal(1.1);
cs.setObject(3, x, Types.DECIMAL);
cs.registerOutParameter(3, Types.DECIMAL);
// parameter 4 is output only
cs.registerOutParameter(4, Types.DECIMAL);
// verify the meta data for the parameters
ParameterMetaData paramMetaData = cs.getParameterMetaData();
assertEquals("Unexpected parameter count", 4, paramMetaData.getParameterCount());
// expected values to be stored in a 2dim. array
String[][] parameterMetaDataArray0 = { // isNullable, isSigned, getPrecision, getScale, getParameterType, getParameterTypeName, getParameterClassName, getParameterMode
{ "PARAMETER_NULLABLE", "true", "5", "3", "3", "DECIMAL", "java.math.BigDecimal", "PARAMETER_MODE_IN" }, { "PARAMETER_NULLABLE", "true", "4", "2", "3", "DECIMAL", "java.math.BigDecimal", "PARAMETER_MODE_IN" }, { "PARAMETER_NULLABLE", "true", "9", "0", "3", "DECIMAL", "java.math.BigDecimal", "PARAMETER_MODE_IN_OUT" }, { "PARAMETER_NULLABLE", "true", "10", "2", "3", "DECIMAL", "java.math.BigDecimal", "PARAMETER_MODE_OUT" } };
testParameterMetaData(cs.getParameterMetaData(), parameterMetaDataArray0);
cs.close();
}
use of java.sql.ParameterMetaData in project derby by apache.
the class ParameterMetaDataJdbc30Test method testParameterMetadataWithTimestampParameters.
/**
* test ParameterMetaData for Java procedures with TIMESTAMP parameters
*
* @exception SQLException if error occurs
*/
public void testParameterMetadataWithTimestampParameters() throws SQLException {
Statement stmt = createStatement();
stmt.execute("CREATE PROCEDURE PMDT(IN pmdI_1 TIMESTAMP, INOUT pmdI_2 TIMESTAMP, OUT pmdI_3 TIMESTAMP) language java parameter style java external name 'org.apache.derbyTesting.functionTests.tests.jdbcapi.ParameterMetaDataJdbc30Test.dummyString'");
CallableStatement cs = prepareCall("CALL PMDT(?, ?, ?)");
// parameter 1 is input only
cs.setTimestamp(1, new Timestamp(0L));
// parameter 2 is input and output
Object x = new Timestamp(2L);
cs.setObject(2, x, Types.CHAR);
cs.registerOutParameter(2, Types.TIMESTAMP);
// parameter 3 is output only
cs.registerOutParameter(3, Types.TIMESTAMP);
// verify the meta data for the parameters
ParameterMetaData paramMetaData = cs.getParameterMetaData();
assertEquals("Unexpected parameter count", 3, paramMetaData.getParameterCount());
// expected values to be stored in a 2dim. array
String[][] parameterMetaDataArray0 = { // isNullable, isSigned, getPrecision, getScale, getParameterType, getParameterTypeName, getParameterClassName, getParameterMode
{ "PARAMETER_NULLABLE", "false", "29", "9", "93", "TIMESTAMP", "java.sql.Timestamp", "PARAMETER_MODE_IN" }, { "PARAMETER_NULLABLE", "false", "29", "9", "93", "TIMESTAMP", "java.sql.Timestamp", "PARAMETER_MODE_IN_OUT" }, { "PARAMETER_NULLABLE", "false", "29", "9", "93", "TIMESTAMP", "java.sql.Timestamp", "PARAMETER_MODE_OUT" } };
testParameterMetaData(cs.getParameterMetaData(), parameterMetaDataArray0);
cs.close();
stmt.execute("DROP PROCEDURE PMDT");
stmt.close();
}
use of java.sql.ParameterMetaData in project derby by apache.
the class ParameterMetaDataJdbc30Test method testParameterMetadataWithCHARParameters.
/**
* test ParameterMetaData for Java procedures with CHAR parameters
*
* @exception SQLException if error occurs
*/
public void testParameterMetadataWithCHARParameters() throws SQLException {
Statement stmt = createStatement();
stmt.execute("CREATE PROCEDURE PMDC(IN pmdI_1 CHAR(10), IN pmdI_2 VARCHAR(25), INOUT pmdI_3 CHAR(19), OUT pmdI_4 VARCHAR(32)) language java parameter style java external name 'org.apache.derbyTesting.functionTests.tests.jdbcapi.ParameterMetaDataJdbc30Test.dummyString'");
CallableStatement cs = prepareCall("CALL PMDC(?, ?, ?, ?)");
// parameters 1 and 2 are input only
cs.setString(1, "TEST0");
cs.setString(2, "TEST1");
// parameter 3 is input and output
Object x = new String("TEST");
cs.setObject(3, x, Types.CHAR);
cs.registerOutParameter(3, Types.CHAR);
// parameter 4 is output only
cs.registerOutParameter(4, Types.CHAR);
// verify the meta data for the parameters
ParameterMetaData paramMetaData = cs.getParameterMetaData();
assertEquals("Unexpected parameter count", 4, paramMetaData.getParameterCount());
// expected values to be stored in a 2dim. array
String[][] parameterMetaDataArray0 = { // isNullable, isSigned, getPrecision, getScale, getParameterType, getParameterTypeName, getParameterClassName, getParameterMode
{ "PARAMETER_NULLABLE", "false", "10", "0", "1", "CHAR", "java.lang.String", "PARAMETER_MODE_IN" }, { "PARAMETER_NULLABLE", "false", "25", "0", "12", "VARCHAR", "java.lang.String", "PARAMETER_MODE_IN" }, { "PARAMETER_NULLABLE", "false", "19", "0", "1", "CHAR", "java.lang.String", "PARAMETER_MODE_IN_OUT" }, { "PARAMETER_NULLABLE", "false", "32", "0", "12", "VARCHAR", "java.lang.String", "PARAMETER_MODE_OUT" } };
testParameterMetaData(cs.getParameterMetaData(), parameterMetaDataArray0);
cs.close();
stmt.execute("DROP PROCEDURE PMDC");
stmt.close();
}
Aggregations