Package java.sql

Examples of java.sql.ParameterMetaData


            * replace with a simple where 1 = ?. Which would take either 1 for true, or 0 for false
     */
          PreparedStatement ps = prepareStatement("select * from t "
              "where 1=? for update");

          ParameterMetaData paramMetaData = ps.getParameterMetaData();
    assertEquals("Unexpected parameter count", 1, 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"}};
View Full Code Here


   * @exception SQLException if error occurs
         */
  public void testSelectStatementUsingNoParameter () throws SQLException {

          PreparedStatement ps = prepareStatement("select * from t");
          ParameterMetaData paramMetaData = ps.getParameterMetaData();
    assertEquals("Unexpected parameter count", 0, paramMetaData.getParameterCount());
   
    //expected values to be stored in a 2dim. array
                String parameterMetaDataArray0 [][] = null;

                testParameterMetaData(paramMetaData, parameterMetaDataArray0);
View Full Code Here

                cs.registerOutParameter(3,Types.INTEGER);
                 //parameter 4 is output only
                 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"},
View Full Code Here

                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"},
View Full Code Here

                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"},
View Full Code Here

                cs.registerOutParameter(2,Types.DECIMAL);
                //parameter 4 is output only
                cs.registerOutParameter(3,Types.DECIMAL);

    //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", "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();

          cs = prepareCall("CALL PMDD(32.4, 47.9, ?, ?)");
    // parameter 3 is input and output
                Object y = new BigDecimal(1.1);
                cs.setObject(1,y, Types.DECIMAL);
                cs.registerOutParameter(1,Types.DECIMAL);
                //parameter 4 is output only
                cs.registerOutParameter(2,Types.DECIMAL);
    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", "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(), parameterMetaDataArray1);

            cs.close();

          cs = prepareCall("CALL PMDD(?, 38.2, ?, ?)");
    // parameters 1 is input only
                cs.setBigDecimal(1,new BigDecimal("1"));;
                // parameter 3 is input and output
                Object z = new BigDecimal(1.1);
                cs.setObject(2,z, Types.DECIMAL);
                cs.registerOutParameter(2,Types.DECIMAL);
                //parameter 4 is output only
                cs.registerOutParameter(3,Types.DECIMAL);

    //verify the meta data for the parameters
                paramMetaData = cs.getParameterMetaData();
    assertEquals("Unexpected parameter count", 3, paramMetaData.getParameterCount());

    //expected values to be stored in a 2dim. array
                String parameterMetaDataArray2 [][] = {
                //isNullable, isSigned, getPrecision, getScale, getParameterType, getParameterTypeName, getParameterClassName, getParameterMode
                {"PARAMETER_NULLABLE", "true", "5", "3", "3", "DECIMAL", "java.math.BigDecimal", "PARAMETER_MODE_IN"},
View Full Code Here

        assertEquals(expectedValues[5], s.getMaxRows());
        assertEquals(expectedValues[6], s.getResultSetHoldability());

        if (s instanceof PreparedStatement) {
            PreparedStatement ps = (PreparedStatement) s;
            ParameterMetaData psmd = ps.getParameterMetaData();
            // Parameter count:
            assertEquals(parameterExpectedValues[0], psmd.getParameterCount());
            for (int i = 1; i <= psmd.getParameterCount(); i++) {
                assertEquals(parameterExpectedValues[i], psmd.getParameterType(i));
            }
        }
    }
View Full Code Here

  private void parseSQLDTA_work(DRDAStatement stmt) throws DRDAProtocolException,SQLException
  {
    String strVal;
    PreparedStatement ps = stmt.getPreparedStatement();
    int codePoint;
    ParameterMetaData pmeta = null;

    // Clear params without releasing storage
    stmt.clearDrdaParams();

    int numVars = 0;
    boolean rtnParam = false;

    reader.markCollection();   
    codePoint = reader.getCodePoint();
    while (codePoint != -1)
    {
        switch (codePoint)
        {
          // required
          case CodePoint.FDODSC:
            while (reader.getDdmLength() > 6) //we get parameter info til last 6 byte
          {
            int dtaGrpLen = reader.readUnsignedByte();
            int numVarsInGrp = (dtaGrpLen - 3) / 3;
            if (SanityManager.DEBUG)
              trace("num of vars in this group is: "+numVarsInGrp);
            reader.readByte();    // tripletType
            reader.readByte();    // id
            for (int j = 0; j < numVarsInGrp; j++)
            {
              final byte t = reader.readByte();
              if (SanityManager.DEBUG)
                trace("drdaType is: "+ "0x" +
                         Integer.toHexString(t));
              int drdaLength = reader.readNetworkShort();
              if (SanityManager.DEBUG)
                trace("drdaLength is: "+drdaLength);
              stmt.addDrdaParam(t, drdaLength);
            }
          }
          numVars = stmt.getDrdaParamCount();
          if (SanityManager.DEBUG)
            trace("numVars = " + numVars);
          if (ps == null)    // it is a CallableStatement under construction
          {
            String marks = "(?"// construct parameter marks
            for (int i = 1; i < numVars; i++)
              marks += ", ?";
            String prepareString = "call " + stmt.procName + marks + ")";
            if (SanityManager.DEBUG)
              trace ("$$ prepareCall is: "+prepareString);
            CallableStatement cs = null;
            try {
              cs = (CallableStatement)
                stmt.prepare(prepareString);     
              stmt.registerAllOutParams();
            } catch (SQLException se) {
              if (! stmt.outputExpected ||
                (!se.getSQLState().equals(SQLState.LANG_NO_METHOD_FOUND)))
                throw se;
              if (SanityManager.DEBUG)
                trace("****** second try with return parameter...");
              // Save first SQLException most likely suspect
              if (numVars == 1)
                prepareString = "? = call " + stmt.procName +"()";
              else
                prepareString = "? = call " + stmt.procName +"("+marks.substring(3) + ")";
              if (SanityManager.DEBUG)
                trace ("$$ prepareCall is: "+prepareString);
              try {
                cs = (CallableStatement) stmt.prepare(prepareString);
              } catch (SQLException se2)
              {
                // The first exception is the most likely suspect
                throw se;
              }
              rtnParam = true;
            }
            ps = cs;
            stmt.ps = ps;
          }

          pmeta = stmt.getParameterMetaData();

          reader.readBytes(6)// descriptor footer
          break;
        // optional
        case CodePoint.FDODTA:
          reader.readByte()// row indicator
          for (int i = 0; i < numVars; i++)
          {
         
            if ((stmt.getParamDRDAType(i+1) & 0x1) == 0x1// nullable
            {
              int nullData = reader.readUnsignedByte();
              if ((nullData & 0xFF) == FdocaConstants.NULL_DATA)
              {
                if (SanityManager.DEBUG)
                  trace("******param null");
                if (pmeta.getParameterMode(i + 1)
                  != JDBC30Translation.PARAMETER_MODE_OUT )
                    ps.setNull(i+1, pmeta.getParameterType(i+1));
                if (stmt.isOutputParam(i+1))
                  stmt.registerOutParam(i+1);
                continue;
              }
            }
View Full Code Here

   */
  private void writeSQLDARD(DRDAStatement stmt, boolean rtnOutput, SQLException e) throws DRDAProtocolException, SQLException
  {
    PreparedStatement ps = stmt.getPreparedStatement();
    ResultSetMetaData rsmeta = ps.getMetaData();
    ParameterMetaData pmeta = stmt.getParameterMetaData();
    int numElems = 0;
    if (e == null || e instanceof SQLWarning)
    {
      if (rtnOutput && (rsmeta != null))
        numElems = rsmeta.getColumnCount();
      else if ((! rtnOutput) && (pmeta != null))
        numElems = pmeta.getParameterCount();
    }

    writer.createDssObject();

    // all went well we will just write a null SQLCA
View Full Code Here

    throws DRDAProtocolException, SQLException
  {

    ResultSet rs = null;
    ResultSetMetaData rsmeta = null;
    ParameterMetaData pmeta = null;
    if (!stmt.needsToSendParamData)
      rs = stmt.getResultSet();
    if (rs == null)    // this is a CallableStatement, use parameter meta data
      pmeta = stmt.getParameterMetaData();
    else
      rsmeta = rs.getMetaData();

      int  numCols = (rsmeta != null ? rsmeta.getColumnCount() : pmeta.getParameterCount());
    int numGroups = 1;
    int colStart = 1;
    int colEnd = numCols;
    int blksize = stmt.getBlksize() > 0 ? stmt.getBlksize() : CodePoint.QRYBLKSZ_MAX;
View Full Code Here

TOP

Related Classes of java.sql.ParameterMetaData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.