Package java.sql

Examples of java.sql.ParameterMetaData


        for (String op : ops) {
            String query = "SELECT entity_id,a_string FROM atable where a_integer" + op + "2" + op + "?=0";
            Connection conn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES));
            PreparedStatement statement = conn.prepareStatement(query);
            statement.setInt(1, 4);
            ParameterMetaData pmd = statement.getParameterMetaData();
            assertEquals(1, pmd.getParameterCount());
            assertEquals(Long.class.getName(), pmd.getParameterClassName(1));
        }
    }
View Full Code Here


    public void testStringConcatMetaData() throws Exception {
      String query = "SELECT entity_id,a_string FROM atable where 2 || a_integer || ? like '2%'";
      Connection conn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES));
      PreparedStatement statement = conn.prepareStatement(query);
      statement.setString(1, "foo");
      ParameterMetaData pmd = statement.getParameterMetaData();
      assertEquals(1, pmd.getParameterCount());
      assertEquals(String.class.getName(), pmd.getParameterClassName(1));

    }
View Full Code Here

    @Test
    public void testRowValueConstructorBindParamMetaData() throws Exception {
        String query = "SELECT a_integer, x_integer FROM aTable WHERE (a_integer, x_integer, a_string) = (?, ?, ?)";
        Connection conn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES));
        PreparedStatement statement = conn.prepareStatement(query);
        ParameterMetaData pmd = statement.getParameterMetaData();
        assertEquals(3, pmd.getParameterCount());
        assertEquals(Integer.class.getName(), pmd.getParameterClassName(1));
        assertEquals(Integer.class.getName(), pmd.getParameterClassName(2));
        assertEquals(String.class.getName(), pmd.getParameterClassName(3));
    }
View Full Code Here

        try {
            while (true) {
                PhoenixPreparedStatement stmt = null;
                try {
                    stmt = new PhoenixPreparedStatement(this, parser);
                    ParameterMetaData paramMetaData = stmt.getParameterMetaData();
                    for (int i = 0; i < paramMetaData.getParameterCount(); i++) {
                        stmt.setObject(i+1, binds.get(bindsOffset+i));
                    }
                    long start = System.currentTimeMillis();
                    boolean isQuery = stmt.execute();
                    if (isQuery) {
                        ResultSet rs = stmt.getResultSet();
                        if (!rs.next()) {
                            if (out != null) {
                                out.println("no rows selected");
                            }
                        } else {
                            int columnCount = 0;
                            if (out != null) {
                                ResultSetMetaData md = rs.getMetaData();
                                columnCount = md.getColumnCount();
                                for (int i = 1; i <= columnCount; i++) {
                                    int displayWidth = md.getColumnDisplaySize(i);
                                    String label = md.getColumnLabel(i);
                                    if (md.isSigned(i)) {
                                        out.print(displayWidth < label.length() ? label.substring(0,displayWidth) : Strings.padStart(label, displayWidth, ' '));
                                        out.print(' ');
                                    } else {
                                        out.print(displayWidth < label.length() ? label.substring(0,displayWidth) : Strings.padEnd(md.getColumnLabel(i), displayWidth, ' '));
                                        out.print(' ');
                                    }
                                }
                                out.println();
                                for (int i = 1; i <= columnCount; i++) {
                                    int displayWidth = md.getColumnDisplaySize(i);
                                    out.print(Strings.padStart("", displayWidth,'-'));
                                    out.print(' ');
                                }
                                out.println();
                            }
                            do {
                                if (out != null) {
                                    ResultSetMetaData md = rs.getMetaData();
                                    for (int i = 1; i <= columnCount; i++) {
                                        int displayWidth = md.getColumnDisplaySize(i);
                                        String value = rs.getString(i);
                                        String valueString = value == null ? QueryConstants.NULL_DISPLAY_TEXT : value;
                                        if (md.isSigned(i)) {
                                            out.print(Strings.padStart(valueString, displayWidth, ' '));
                                        } else {
                                            out.print(Strings.padEnd(valueString, displayWidth, ' '));
                                        }
                                        out.print(' ');
                                    }
                                    out.println();
                                }
                            } while (rs.next());
                        }
                    } else if (out != null){
                        int updateCount = stmt.getUpdateCount();
                        if (updateCount >= 0) {
                            out.println((updateCount == 0 ? "no" : updateCount) + (updateCount == 1 ? " row " : " rows ") + stmt.getUpdateOperation().toString());
                        }
                    }
                    bindsOffset += paramMetaData.getParameterCount();
                    double elapsedDuration = ((System.currentTimeMillis() - start) / 1000.0);
                    out.println("Time: " + elapsedDuration + " sec(s)\n");
                    nStatements++;
                } finally {
                    if (stmt != null) {
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

          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 " +
                         " tablename like ? and tableID 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

          //variation 1, testing DERBY-44
          PreparedStatement ps = prepareStatement("select * from sys.systables " +
              "where tablename like ? escape ?");
          ps.setString (1, "SYS%");
          ps.setString (2, "");
          ParameterMetaData paramMetaData = ps.getParameterMetaData();
    assertEquals("Unexpected parameter count", 2, paramMetaData.getParameterCount());

    //expected values to be stored in a 2dim. array
                String parameterMetaDataArray0 [][] = {
                //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

     */
          PreparedStatement ps = prepareStatement("select * from sys.systables " +
              "where tablename like 'SYS%' and " +
              "tableID like '8000001%'");

          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

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.