Package java.sql

Examples of java.sql.ParameterMetaData


            }
            }
            // TF:24/07/2008:Added support for columns descriptors on input data sets too
            else if (statement != null && this.inputColMapping != null) { //PM:Aug 15, 2008:added null check on inputColMapping
              // It's possibly a request for the column list off the input metadata
              ParameterMetaData data = null;
              try {
                data = statement.getParameterMetaData();
              }
              catch (Exception e) {
                // No dice, go with what we've got
              }
              int numCols = this.inputColMapping.size();
              for (int i = 0; i < numCols; i++) {
                String name =  ":" + this.inputColMapping.get(i);
                int type = Types.OTHER;
                try {
                  if (data != null) {
                    type = data.getParameterType(i);
                  }
                }
                catch (Exception e) {}
                int scale = 2;
                try {
                  if (data != null) {
                    scale = data.getPrecision(i);
                  }
                }
                catch (Exception e) {};
                cds.add(new DBColumnDesc(4, type, type, name, false, scale));
              }
            }
            else if (resultSet != null) {
              ResultSetMetaData data = this.resultSet.getMetaData();
                int numCols = data.getColumnCount();
                // AD:24/09/08 Column Count starts at 1 not 0
                for (int i = 1; i <= numCols; i++) {
                    cds.add(new DBColumnDesc(data, i));
                }
            }
View Full Code Here


      createProcedure("bar",
          "(x char(16), y int, z DECIMAL(10)) insert into test.t1 values (x, y);");
      cstmt = this.conn.prepareCall("{CALL bar(?, ?, ?)}");

      if (!isRunningOnJdk131()) {
        ParameterMetaData md = cstmt.getParameterMetaData();
        assertEquals(3, md.getParameterCount());
        assertEquals(Types.CHAR, md.getParameterType(1));
        assertEquals(Types.INTEGER, md.getParameterType(2));
        assertEquals(Types.DECIMAL, md.getParameterType(3));
      }

      createProcedure("p", "() label1: WHILE @a=0 DO SET @a=1; END WHILE");
      this.conn.prepareCall("{CALL p()}");

      createFunction("f", "() RETURNS INT NO SQL return 1; ");
      cstmt = this.conn.prepareCall("{? = CALL f()}");

      if (!isRunningOnJdk131()) {
        ParameterMetaData md = cstmt.getParameterMetaData();
        assertEquals(Types.INTEGER, md.getParameterType(1));
      }
    } finally {
      if (cstmt != null) {
        cstmt.close();
      }
View Full Code Here

    checkInterfaceImplemented(java.sql.Statement.class.getMethods(),
        stmtToCheck.getClass(), stmtToCheck);

    PreparedStatement pStmtToCheck = connToCheck
        .prepareStatement("SELECT 1");
    ParameterMetaData paramMd = pStmtToCheck.getParameterMetaData();

    checkInterfaceImplemented(
        java.sql.PreparedStatement.class.getMethods(),
        pStmtToCheck.getClass(), pStmtToCheck);
    checkInterfaceImplemented(
        java.sql.ParameterMetaData.class.getMethods(),
        paramMd.getClass(), paramMd);

    pStmtToCheck = ((com.mysql.jdbc.Connection) connToCheck)
        .serverPrepareStatement("SELECT 1");

    checkInterfaceImplemented(
View Full Code Here

            }
            }
            // TF:24/07/2008:Added support for columns descriptors on input data sets too
            else if (statement != null && this.inputColMapping != null) { //PM:Aug 15, 2008:added null check on inputColMapping
              // It's possibly a request for the column list off the input metadata
              ParameterMetaData data = null;
              try {
                data = statement.getParameterMetaData();
              }
              catch (Exception e) {
                // No dice, go with what we've got
              }
              int numCols = this.inputColMapping.size();
              for (int i = 0; i < numCols; i++) {
                String name =  ":" + this.inputColMapping.get(i);
                int type = Types.OTHER;
                try {
                  if (data != null) {
                    type = data.getParameterType(i);
                  }
                }
                catch (Exception e) {}
                int scale = 2;
                try {
                  if (data != null) {
                    scale = data.getPrecision(i);
                  }
                }
                catch (Exception e) {};
                cds.add(new DBColumnDesc(4, type, type, name, false, scale));
              }
            }
            else if (resultSet != null) {
              ResultSetMetaData data = this.resultSet.getMetaData();
                int numCols = data.getColumnCount();
                // AD:24/09/08 Column Count starts at 1 not 0
                for (int i = 1; i <= numCols; i++) {
                    cds.add(new DBColumnDesc(data, i));
                }
            }
View Full Code Here

            }
            }
            // TF:24/07/2008:Added support for columns descriptors on input data sets too
            else if (statement != null && this.inputColMapping != null) { //PM:Aug 15, 2008:added null check on inputColMapping
              // It's possibly a request for the column list off the input metadata
              ParameterMetaData data = null;
              try {
                data = statement.getParameterMetaData();
              }
              catch (Exception e) {
                // No dice, go with what we've got
              }
              int numCols = this.inputColMapping.size();
              for (int i = 0; i < numCols; i++) {
                String name =  ":" + this.inputColMapping.get(i);
                int type = Types.OTHER;
                try {
                  if (data != null) {
                    type = data.getParameterType(i);
                  }
                }
                catch (Exception e) {}
                int scale = 2;
                try {
                  if (data != null) {
                    scale = data.getPrecision(i);
                  }
                }
                catch (Exception e) {};
                cds.add(new DBColumnDesc(4, type, type, name, false, scale));
              }
            }
            else if (resultSet != null) {
              ResultSetMetaData data = this.resultSet.getMetaData();
                int numCols = data.getColumnCount();
                // AD:24/09/08 Column Count starts at 1 not 0
                for (int i = 1; i <= numCols; i++) {
                    cds.add(new DBColumnDesc(data, 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

          Object x = new Integer(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"},
View Full Code Here

          ps.setInt(2, 1);
          ps.setNull(3, java.sql.Types.INTEGER);
          ps.setBigDecimal(4,new BigDecimal("1"));
          ps.setNull(5, java.sql.Types.DATE);

          ParameterMetaData paramMetaData = ps.getParameterMetaData();
    assertEquals("Unexpected parameter count", 5, paramMetaData.getParameterCount());

    //expected values to be stored in a 2dim. array
                String [][] parameterMetaDataArray0 = {
                //isNullable, isSigned, getPrecision, getScale, getParameterType, getParameterTypeName, getParameterClassName, getParameterMode
                {"PARAMETER_NULLABLE", "false", "5", "0", "1", "CHAR", "java.lang.String", "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_IN"},
                {"PARAMETER_NULLABLE", "true", "5", "0", "3", "DECIMAL", "java.math.BigDecimal", "PARAMETER_MODE_IN"},
                {"PARAMETER_NULLABLE", "false", "10", "0", "91", "DATE", "java.sql.Date", "PARAMETER_MODE_IN"}};

                testParameterMetaData(paramMetaData, parameterMetaDataArray0);
 
    /*
           *  JCC seems to report these parameters as MODE_UNKNOWN, where as Derby uses MODE_IN
           *  JCC behaviour with network server matches its behaviour with DB2
           *  getPrecision() returns 0 for CHAR/DATE/BIT types for Derby. JCC shows maxlen
     */
          ps.execute();

    /*
     * bug 4533 - associated parameters should not be included in the parameter meta data list
           * Following statement systab will generate 4 associated parameters for the 2
           * user parameters. This results in total 6 parameters for the prepared statement
           * internally. But we should only show 2 user visible parameters through
           * getParameterMetaData().
     */
          ps = prepareStatement("select * from sys.systables where " +
                         " CAST(tablename AS VARCHAR(128)) like ? and CAST(tableID AS CHAR(36)) like ?");
          ps.setString (1, "SYS%");
          ps.setString (2, "8000001%");
          paramMetaData = ps.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", "false", "128", "0", "12", "VARCHAR", "java.lang.String", "PARAMETER_MODE_IN"},
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.