Package java.sql

Examples of java.sql.ResultSetMetaData


            schemaPattern = PERCENT;
        }
        // list which represent records containing schema info
        List records = new ArrayList ();

        ResultSetMetaData rmetadata = null;
        ResultSetImpl results = null;
        PreparedStatementImpl prepareQuery = null;
        try {
            prepareQuery = driverConnection.prepareStatement(QUERY_SCHEMAS);
            prepareQuery.setObject(1, catalog.toUpperCase());
View Full Code Here


  private Vector executeQuery(String query, ArrayList bindObjects) throws Exception
  {
    try {
      prepareQuery(query, bindObjects);
      ResultSet resultSet = dataAccessLayer.executeQueryNonParsed();
      ResultSetMetaData metaData = resultSet.getMetaData();
      int size = metaData.getColumnCount();
      Vector result = new Vector();
      ArrayList resultItem = null;
      while (resultSet.next()) {
        resultItem = new ArrayList();
        for (int i = 0; i < size; ++i) {
View Full Code Here

      try {
        String query = getQueryForResultReport(userId, reportId, search, dataAccessLayer);

        dataAccessLayer.setSqlQuery(query);
        resultSet = dataAccessLayer.executeQueryNonParsed();
        ResultSetMetaData metaData = resultSet.getMetaData();
        int cols = metaData.getColumnCount();
        int i = 0;
        boolean exclude = false;
        boolean[] isDate = new boolean[cols + 1];
        for (i = 1; i <= cols; i++) {
          isDate[i] = false;
        }
        for (i = 1; i <= cols; i++) {
          if ((Types.DATE == metaData.getColumnType(i) || Types.TIMESTAMP == metaData.getColumnType(i))
              && !metaData.getColumnName(i).equalsIgnoreCase("Modified") && !metaData.getColumnName(i).equalsIgnoreCase("Created")) {
            isDate[i] = true;
          }
        } // end for ( i = 1; i <= cols; i++)

        while (resultSet.next()) {
View Full Code Here

   */
  private String getDisplayableResultSetRow() {
    StringBuffer displayableResultSetRow = new StringBuffer();

    try {
      ResultSetMetaData md = real.getMetaData();
      for ( int i = 1; i <= md.getColumnCount(); i++) {
        displayableResultSetRow.append(md.getColumnName(i))
          .append('=');
        switch ( md.getColumnType(i)) {
          case Types.ARRAY:
          case Types.BLOB:
          case Types.CHAR:
          case Types.CLOB:
          case Types.DATALINK:
          case Types.DATE:
          case Types.JAVA_OBJECT:
          case Types.LONGVARBINARY:
          case Types.LONGVARCHAR:
          case Types.REF:
          case Types.TIME:
          case Types.TIMESTAMP:
          case Types.VARBINARY:
          case Types.VARCHAR:      if ( real.getString(i)!=null) {
                          displayableResultSetRow.append('\'').append(real.getString(i)).append('\'');
                        } else {
                          displayableResultSetRow.append("NULL");
                        }
                        break;
          case Types.NULL:      displayableResultSetRow.append("NULL");
                        break;
          default:          if ( real.getString(i)!=null) {
                          displayableResultSetRow.append(real.getString(i));
                        } else {
                          displayableResultSetRow.append("NULL");
                        }
                        break;
        }

        displayableResultSetRow.append(',');
      }
      if ( md.getColumnCount() >= 1) {
        displayableResultSetRow.deleteCharAt(displayableResultSetRow.length()-1);
      }
    } catch ( SQLException e) {
      if ( log.isErrorEnabled()) log.error(getId()+":unable to display resultset row",e);
    }
View Full Code Here

    // We run the query to get meta-information about the columns.
    @SuppressWarnings("unused") Class<?> jdbcDriver = Class.forName( jsapResult.getString( "jdbcDriver" ) );
    Connection connection = DriverManager.getConnection( jsapResult.getString( "dburi" ) );
    Statement s = connection.createStatement();
    ResultSet rs = s.executeQuery( "SELECT " + jsapResult.getString( "select" ) );
    ResultSetMetaData metaData = rs.getMetaData();   
    String[] column = new String[ metaData.getColumnCount() - 2 ];
    for( int i = 3; i <= metaData.getColumnCount(); i++ ) column[ i - 3 ] = metaData.getColumnName( i );
    rs.close();
    s.close();
    connection.close();
   
    final DocumentFactory[] factory = new DocumentFactory[ column.length ];
View Full Code Here

      (final ResultSet rs, final boolean labelMapping)
      throws SQLException
  {
    try
    {
      final ResultSetMetaData rsmd = rs.getMetaData();
      final int colcount = rsmd.getColumnCount();
      final Object[] header = new Object[colcount];
      final Class[] colTypes = TypeMapper.mapTypes(rsmd);
      final DefaultTableMetaData metaData = new DefaultTableMetaData(colcount);
      for (int i = 0; i < colcount; i++)
      {
        if (labelMapping)
        {
          final String name = rsmd.getColumnLabel(i + 1);
          header[i] = name;
        }
        else
        {
          final String name = rsmd.getColumnName(i + 1);
          header[i] = name;
        }

        ResultSetTableModelFactory.updateMetaData(rsmd, metaData, i);
      }
View Full Code Here

    }
    return results;
  }

  protected void saveMetaData(ResultSet rs) throws SQLException {
    ResultSetMetaData metadata = rs.getMetaData();
    columnCount = metadata.getColumnCount();
    columnNames = new String[columnCount];
    columnTypes = new int[columnCount];
    for (int col = 1; col <= columnCount; ++col) {
      columnNames[col - 1] = metadata.getColumnName(col);
      columnTypes[col - 1] = metadata.getColumnType(col);
    }
  }
View Full Code Here

            if (module.isAbstract()) continue;
           
            try {
                String sql = "select top 1 * from " + module.getTableName();
                ResultSet rs = DatabaseManager.executeSQL(sql);
                ResultSetMetaData md = rs.getMetaData();
               
                String columnName;
                boolean remove;
                for (int i = 1; i < md.getColumnCount() + 1; i++) {
                  columnName = md.getColumnName(i);
                  remove = false;
                 
                    if (!columnName.startsWith("_KEEP_")) {
                        for (DcField field : module.getFields()) {
                            if (columnName.equalsIgnoreCase(field.getDatabaseFieldName()))
View Full Code Here

                if (p == null) {
                    sendErrorResponse("Portal not found: " + name);
                } else {
                    PreparedStatement prep = p.prep.prep;
                    try {
                        ResultSetMetaData meta = prep.getMetaData();
                        sendRowDescription(meta);
                    } catch (Exception e) {
                        sendErrorResponse(e);
                    }
                }
            } else {
                server.trace("expected S or P, got " + type);
                sendErrorResponse("expected S or P");
            }
            break;
        }
        case 'E': {
            String name = readString();
            server.trace("Execute");
            Portal p = portals.get(name);
            if (p == null) {
                sendErrorResponse("Portal not found: " + name);
                break;
            }
            int maxRows = readShort();
            Prepared prepared = p.prep;
            JdbcPreparedStatement prep = prepared.prep;
            server.trace(prepared.sql);
            try {
                prep.setMaxRows(maxRows);
                boolean result = prep.execute();
                if (result) {
                    try {
                        ResultSet rs = prep.getResultSet();
                        ResultSetMetaData meta = rs.getMetaData();
                        sendRowDescription(meta);
                        while (rs.next()) {
                            sendDataRow(rs);
                        }
                        sendCommandComplete(prep, 0);
                    } catch (Exception e) {
                        sendErrorResponse(e);
                    }
                } else {
                    sendCommandComplete(prep, prep.getUpdateCount());
                }
            } catch (Exception e) {
                sendErrorResponse(e);
            }
            break;
        }
        case 'S': {
            server.trace("Sync");
            sendReadyForQuery();
            break;
        }
        case 'Q': {
            server.trace("Query");
            String query = readString();
            ScriptReader reader = new ScriptReader(new StringReader(query));
            while (true) {
                JdbcStatement stat = null;
                try {
                    String s = reader.readStatement();
                    if (s == null) {
                        break;
                    }
                    s = getSQL(s);
                    stat = (JdbcStatement) conn.createStatement();
                    boolean result = stat.execute(s);
                    if (result) {
                        ResultSet rs = stat.getResultSet();
                        ResultSetMetaData meta = rs.getMetaData();
                        try {
                            sendRowDescription(meta);
                            while (rs.next()) {
                                sendDataRow(rs);
                            }
View Full Code Here

        return new Csv();
    }

    private int writeResultSet(ResultSet rs) throws SQLException {
        try {
            ResultSetMetaData meta = rs.getMetaData();
            int rows = 0;
            int columnCount = meta.getColumnCount();
            String[] row = new String[columnCount];
            for (int i = 0; i < columnCount; i++) {
                row[i] = meta.getColumnLabel(i + 1);
            }
            writeRow(row);
            while (rs.next()) {
                for (int i = 0; i < columnCount; i++) {
                    row[i] = rs.getString(i + 1);
View Full Code Here

TOP

Related Classes of java.sql.ResultSetMetaData

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.