Package java.sql

Examples of java.sql.ParameterMetaData


        rs.next();
        assertEquals(6, rs.getInt(1));
        stat.execute("deallocate test");

        PreparedStatement prep = conn.prepareStatement("insert into test values(?, ?)");
        ParameterMetaData meta = prep.getParameterMetaData();
        assertEquals(2, meta.getParameterCount());
        prep.setInt(1, 1);
        prep.setString(2, "Hello");
        prep.execute();
        rs = stat.executeQuery("select * from test");
        rs.next();
View Full Code Here


        s.executeUpdate("DROP TABLE IF EXISTS TEST");
    }

    private void testParameterMetaData(Connection conn) throws SQLException {
        PreparedStatement prep = conn.prepareStatement("SELECT ?, ?, ? FROM DUAL");
        ParameterMetaData pm = prep.getParameterMetaData();
        assertEquals("java.lang.String", pm.getParameterClassName(1));
        assertEquals("VARCHAR", pm.getParameterTypeName(1));
        assertEquals(3, pm.getParameterCount());
        assertEquals(ParameterMetaData.parameterModeIn, pm.getParameterMode(1));
        assertEquals(Types.VARCHAR, pm.getParameterType(1));
        assertEquals(0, pm.getPrecision(1));
        assertEquals(0, pm.getScale(1));
        assertEquals(ResultSetMetaData.columnNullableUnknown, pm.isNullable(1));
        assertEquals(pm.isSigned(1), true);
        assertThrows(ErrorCode.INVALID_VALUE_2, pm).getPrecision(0);
        assertThrows(ErrorCode.INVALID_VALUE_2, pm).getPrecision(4);
        prep.close();
        assertThrows(ErrorCode.OBJECT_CLOSED, pm).getPrecision(1);
View Full Code Here

        stat.execute("DROP TABLE TEST3");
    }

    private void checkParameter(PreparedStatement prep, int index,
            String className, int type, String typeName, int precision, int scale) throws SQLException {
        ParameterMetaData meta = prep.getParameterMetaData();
        assertEquals(className, meta.getParameterClassName(index));
        assertEquals(type, meta.getParameterType(index));
        assertEquals(typeName, meta.getParameterTypeName(index));
        assertEquals(precision, meta.getPrecision(index));
        assertEquals(scale, meta.getScale(index));
    }
View Full Code Here

      try { if (oConn.getDataBaseProduct()!=JDCConnection.DBMS_POSTGRESQL) oStmt.setQueryTimeout(iTimeOut); } catch (SQLException sqle) { if (DebugFile.trace) DebugFile.writeln("Error at PreparedStatement.setQueryTimeout(" + String.valueOf(iTimeOut) + ")" + sqle.getMessage()); }

      for (int p=0; p<aFilterValues.length; p++) {
        Object oParam = aFilterValues[p];
        if (null==oParam) {
          ParameterMetaData oParMDat = oStmt.getParameterMetaData();
          int pType;
          try {
            pType = oParMDat.getParameterType(p+1);
          } catch (SQLException parameternotavailable) {
            if (DebugFile.trace) {
              DebugFile.writeln("DBSubset.load() : SQLException "+parameternotavailable.getMessage()+" at ParameterMetaData.getParameterType("+String.valueOf(p+1)+")");
          }
          pType = Types.NULL;
View Full Code Here

         ResultSetMetaData rmd = (ResultSetMetaData) value;
         value = new SerializableResultSetMetaData(rmd);
      }
      else if ( value instanceof ParameterMetaData )
      {
         ParameterMetaData pmd = (ParameterMetaData) value;
         value = new SerializableParameterMetaData(pmd);
      }
      else if( value != null && (value instanceof Serializable) == false )
      {
         throw new IllegalAccessException("Method="+method+" does not return Serializable");
View Full Code Here

   */
  protected int getParamPrecision(int index) throws SQLException
  {
    if (ps != null && ps instanceof CallableStatement)
    {
      ParameterMetaData pmeta = getParameterMetaData();

      return Math.min(pmeta.getPrecision(index),
              FdocaConstants.NUMERIC_MAX_PRECISION);

    }
    else
      return -1;
View Full Code Here

   */
  protected int getParamScale(int index) throws SQLException
  {
    if (ps != null && ps instanceof CallableStatement)
    {
      ParameterMetaData pmeta = getParameterMetaData();
      return Math.min(pmeta.getScale(index),FdocaConstants.NUMERIC_MAX_PRECISION);
    }
    else
      return -1;
  }
View Full Code Here

        
  }

  private void setupCallableStatementParams(CallableStatement cs) throws SQLException
  {
    ParameterMetaData pmeta = getParameterMetaData();
    int numElems = pmeta.getParameterCount();

    for ( int i = 0; i < numElems; i ++)
    {
      boolean outputFlag = false;
     
      int parameterMode = pmeta.getParameterMode(i + 1);
      int parameterType = pmeta.getParameterType(i + 1);
                        int parameterPrecision = pmeta.getPrecision(i + 1);
                        int parameterScale = pmeta.getScale(i + 1);

      switch (parameterMode) {
        case JDBC30Translation.PARAMETER_MODE_IN:
          break;
        case JDBC30Translation.PARAMETER_MODE_OUT:
        case JDBC30Translation.PARAMETER_MODE_IN_OUT:
          outputFlag = true;
          break;
        case JDBC30Translation.PARAMETER_MODE_UNKNOWN:
          // It's only unknown if array
          String objectType = pmeta.getParameterClassName(i+1);
          parameterType =
            getOutputParameterTypeFromClassName(objectType);
          if (parameterType  != NOT_OUTPUT_PARAM)
            outputFlag = true;
      }
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

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.