Package java.sql

Examples of java.sql.ResultSetMetaData


    * @param rs
    * @param conn
    * @throws SQLException
    */
   public SqlRow fillOneRowWithStringEntriesDEPRECATED(ResultSet rs, I_AttributeTransformer transformer) throws Exception {
      ResultSetMetaData meta = rs.getMetaData();
      int numberOfColumns = meta.getColumnCount();
      int count = getRowCount();
      SqlRow row = new SqlRow(this.info, count);
      getRows().add(row);
      for (int i=1; i<=numberOfColumns; i++) {
         String value = rs.getString(i);
         ClientProperty prop = new ClientProperty(meta.getColumnName(i), null, null, value);
         row.setColumn(prop);
      }
      if (transformer != null) {
         Map attr = transformer.transform(rs, count);
         if (attr != null)
View Full Code Here


    * @param rs
    * @param conn
    * @throws SQLException
    */
   public SqlRow fillOneRowWithObjects(ResultSet rs, I_AttributeTransformer transformer) throws Exception {
      ResultSetMetaData meta = rs.getMetaData();
      int numberOfColumns = meta.getColumnCount();
      int count = getRowCount();
      SqlRow row = new SqlRow(this.info, count);
      getRows().add(row);
      for (int i=1; i<=numberOfColumns; i++) {
         ClientProperty prop = buildClientProperty(meta, rs, i);
View Full Code Here

   * k_prod_locats with gu_product equal to this Product GUID.
   * @throws SQLException
   */
  public ProductLocation getFirstLocation(JDCConnection oConn) throws SQLException {
    ResultSet oRSet;
    ResultSetMetaData oMeta;
    PreparedStatement oStmt;
    ProductLocation oLoca;
    Object oVal;
    int iColCount;

    if (DebugFile.trace) {
      DebugFile.writeln("Begin Product.getFirstLocation()" );
      DebugFile.incIdent();
    }

    oStmt = oConn.prepareStatement("SELECT l.* FROM " + DB.k_prod_locats + " l, " + DB.k_products + " p WHERE l." + DB.gu_product + "=p." + DB.gu_product + " AND p." + DB.gu_product + "=?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);

    oStmt.setString(1,getString(DB.gu_product));
    oRSet = oStmt.executeQuery();

    if (oRSet.next()) {
      oLoca = new ProductLocation();
      oMeta = oRSet.getMetaData();
      iColCount = oMeta.getColumnCount();

      for (int iCol=1; iCol<=iColCount; iCol++) {
        oVal = oRSet.getObject(iCol);
        if (null!=oVal) oLoca.put(oMeta.getColumnName(iCol).toLowerCase(), oVal);
      }
    }
    else
      oLoca = null;

View Full Code Here

    // ***************************
    // Get k_thesauri columns list

    Statement oStmt = oConn.createStatement();
    ResultSet oRSet = oStmt.executeQuery("SELECT * FROM " + DB.k_thesauri + " WHERE 1=0");
    ResultSetMetaData oMDat = oRSet.getMetaData();

    int iCols = oMDat.getColumnCount();
    String[] aColArray = new String[iCols];
    StringBuffer sColList = new StringBuffer(32*iCols);

    for (int c=0; c<iCols; c++) {
      aColArray[c] = oMDat.getColumnName(c+1).toLowerCase();
      sColList.append(aColArray[c]);
      if (c!=iCols-1) sColList.append(",");
    }

    oRSet.close();
View Full Code Here

      if (this.dbSpecific.isDatasourceReadonly()) {
         this.sqlInfo.fillOneRowWithObjects(rs, this.transformer);
         return;
      }

      ResultSetMetaData meta = rs.getMetaData();
      int numberOfColumns = meta.getColumnCount();
    
      if (numberOfColumns < 11)
         throw new Exception("ReplicationConverter.addInfo: wrong number of columns: should be at least 11 but was " + numberOfColumns);
     
      /*
 
View Full Code Here

    oRSet.close();
    oStmt.close();

    oStmt = oConn.createStatement();
    oRSet = oStmt.executeQuery("SELECT * FROM " + DB.k_addresses + " WHERE 1=0");
    ResultSetMetaData oMDat = oRSet.getMetaData();
    StringBuffer oColumnList = new StringBuffer(512);
    int iColumnCount = oMDat.getColumnCount();

    for (int c=1; c<=iColumnCount; c++) {
      if (c>1) oColumnList.append(',');
      oColumnList.append("a." + oMDat.getColumnName(c).toLowerCase());
    } // next (c)

    oRSet.close();
    oStmt.close();

View Full Code Here

    Vector oRow;
    HashMap oTransforms;
    Object oOriginalValue;
    Object oTransformedValue;
    ResultSet oRSet;
    ResultSetMetaData oRDat;
    DataRowSet oDatR;
    String sColName;
    DataTblDef oMDat = OrMetaData[iTable];
    DataTransformation oDatT;
    PreparedStatement oStmt = OrStatements[iTable];
    PreparedStatement oStmt2;

    // Asignar los parametros de la clave primaria para leer valores en origen

    oDatR = getRowSet(iTable);
    // Comprobar primero si existen parámetros en la cláusula WHERE
    if (oDatR.WhereClause!=null) {
      if (oDatR.WhereClause.indexOf("?")>0) {
        for (int p=0;p<cParams; p++) {
          if (DebugFile.trace) DebugFile.writeln ("binding query input parameter " + String.valueOf(p+1));
          oStmt.setObject(p+1, OrPK[p]);
        } // next (p)
      } // fi (oDatR.WhereClause.indexOf("?")>0)
    } // fi (oDatR.WhereClause!=null)

    if (DebugFile.trace) DebugFile.writeln ("PreparedStatement.executeQuery()");

    oRSet = oStmt.executeQuery(); // Ejecutar la query de lectura de registros

    /* Not supported under PostgreSQL 7.3.4
    if (DebugFile.trace) DebugFile.writeln ("ResultSet.setFetchSize(" + String.valueOf(iFetchBurst) + ")");

    oRSet.setFetchSize (iFetchBurst); // Asignar el tamaño de ráfaga de vuelta
    */

    oDatR = null;

    if (DebugFile.trace) {
      if (DataRowSets.get(iTable)!=null)
        DebugFile.writeln ("FieldList=" + getRowSet(iTable).FieldList);
      else
        DebugFile.writeln ("ERROR: getRowSet(" + String.valueOf(iTable) + ") == null");
    }

    // Si se especificó explícitamente una lista de campos a leer,
    // entonces tomar como número de columnas la del Origen,
    // en otro caso tomar como número de columnas las del Destino.
    if (getRowSet(iTable).FieldList.compareTo("*")!=0)
      iCols = oRSet.getMetaData().getColumnCount();
    else
      iCols = TrMetaData[iTable].ColCount;

    if (DebugFile.trace) DebugFile.writeln ("reading " + String.valueOf(iCols) + " columns");

    // Guardar los resultados en una matriz bidimensional almacenada como un vector de filas
    oResults = new Vector(iFetchBurst, iFetchBurst);

    if (DebugFile.trace) DebugFile.writeln ("new Vector(" + String.valueOf(iFetchBurst) + ")");

    iRows = 0;

    try {
      // Obtener una referencia a las transformaciones de datos para el RowSet actual
      oTransforms = (HashMap) Transformations.get(iTable);
      cTransforms = oTransforms.size();
    }
    catch (ArrayIndexOutOfBoundsException e) {
      if (DebugFile.trace) DebugFile.writeln ("table has no transformation replacements");
      oTransforms = null;
      cTransforms = 0;
    }

    if (0 == cTransforms) {
      // Si no hay transformaciones para campos, usar un algoritmo más rápido con menos condiciones
      while (oRSet.next() && iRows<iFetchBurst) {
        iRows++;
        if (DebugFile.trace) DebugFile.writeln ("caching row " + String.valueOf(iRows));
        oRow = new Vector(iCols);
        for (int c=1; c<=iCols; c++)
          oRow.add(oRSet.getObject(c));
        oResults.add(oRow);
      } // wend ()
    }
    else { // Algoritmo con más condiciones para el caso de reemplazo de transformación de datos
      oRDat = oRSet.getMetaData(); // Alias rápido a los metadatos del ResultSet
      while (oRSet.next() && iRows<iFetchBurst) {
        iRows++;
        if (DebugFile.trace) DebugFile.writeln ("caching row " + String.valueOf(iRows));
        // Crear un vector para la fila
        oRow = new Vector(iCols);
        // Recorer cada columna y almacenar su valor en el vector fila
        iPK = 0;
        for (int c=1; c<=iCols; c++) {
          try {
            // Obtener una referencia a la transformación para la columna actual
            // si no hay transformación saltará una excepción y el valor de la
            // columna se asignará en la sección catch()
            sColName = oRDat.getColumnName(c);

            oDatT = (DataTransformation) oTransforms.get(sColName);

            // Asignar el valor transformado del campo
            if (null==oDatT)
View Full Code Here

   * @throws SQLException
   */
  public Map<String, String> getColumnData (ResultSet set) throws SQLException {
    Map<String, String> cd = new LinkedHashMap<String, String>();
   
    ResultSetMetaData md = set.getMetaData();
    for (int c=1; c<=md.getColumnCount(); c++) {
      cd.put(md.getColumnName(c), md.getColumnClassName(c));
    }
   
    return cd;
  }
View Full Code Here

    String sNeighbour;
    boolean bDoNext;
    PreparedStatement oCstm;
    PreparedStatement oStmt;
    ResultSet oRSet;
    ResultSetMetaData oMDat;
   
    LinkedList<Category> oCatList = new LinkedList<Category>();
    Category oCatg;

    if (DebugFile.trace) {
      DebugFile.writeln("Begin Category.browse([Connection], ...)");     
      DebugFile.incIdent();
      DebugFile.writeln((iDirection==Category.BROWSE_UP ? DB.gu_child_cat : DB.gu_parent_cat) + "=" + sCatId);
    }

  oCstm = oConn.prepareStatement("SELECT * FROM "+DB.k_categories+" WHERE "+DB.gu_category+"=?",
                                 ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);

    if (iDirection==Category.BROWSE_UP) {
      if (DebugFile.trace) DebugFile.writeln("Connection.prepareStatement(SELECT " + DB.gu_parent_cat + " FROM " + DB.k_cat_tree + " WHERE " + DB.gu_child_cat + "=?)");
      oStmt = oConn.prepareStatement("SELECT " + DB.gu_parent_cat + " FROM " + DB.k_cat_tree + " WHERE " + DB.gu_child_cat + "=?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
    }
    else {
      if (DebugFile.trace) DebugFile.writeln("Connection.prepareStatement(SELECT " + DB.gu_child_cat + " FROM " + DB.k_cat_tree + " WHERE " + DB.gu_parent_cat + "=?)");
      oStmt = oConn.prepareStatement("SELECT " + DB.gu_child_cat + " FROM " + DB.k_cat_tree + " WHERE " + DB.gu_parent_cat + "=?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
    }

    do {

      if (DebugFile.trace) DebugFile.writeln("PreparedStatement.setString(1, " + sCatId + ")");

      oStmt.setString(1, sCatId);
      oRSet = oStmt.executeQuery();
      bDoNext = oRSet.next();

      if (bDoNext) {
        sNeighbour = oRSet.getString(1);
        if (DebugFile.trace) DebugFile.writeln("do next is true with "+(iDirection==Category.BROWSE_UP ? DB.gu_parent_cat : DB.gu_child_cat) + "=" + sNeighbour);
      }
      else {
        sNeighbour = "";
        if (DebugFile.trace) DebugFile.writeln("do next is false");
      }

      oRSet.close();

      if (bDoNext) {
        if (sCatId.equals(sNeighbour)) {
          bDoNext = false;
        }
        else {
          // Do not replace this code by new Category(oConn, sNeighbour);
          // It is being called from Product.getShopId which JDCConnection
          // does not have any metadata for calling the Category constructor
          oCstm.setString(1, sNeighbour);
          oRSet = oCstm.executeQuery();
          oRSet.next();
          oMDat = oRSet.getMetaData();
          int nCols = oMDat.getColumnCount();                   
          oCatg = new Category();
          for (int c=1; c<=nCols; c++) {
            oCatg.put(oMDat.getColumnName(c).toLowerCase(), oRSet.getObject(c));
          }         
          oRSet.close();         

          if (iDirection==Category.BROWSE_UP)
            if (iOrder==Category.BROWSE_BOTTOMUP)
View Full Code Here

   */
  public void readColumns(Connection oConn, DatabaseMetaData oMData) throws SQLException {
      int iErrCode;
      Statement oStmt;
      ResultSet oRSet;
      ResultSetMetaData oRData;
      DBColumn oCol;
      String sCol;
      int iCols;
      ListIterator oColIterator;

      String sColName;
      short iSQLType;
      String sTypeName;
      int iPrecision;
      int iDigits;
      int iNullable;
      int iColPos;

      int iDBMS;

      String sGetAllCols = "";
      String sSetPKCols = "";
      String sSetAllCols = "";
      String sSetNoPKCols = "";

      oColumns = new LinkedList<DBColumn>();
    oIndexes = new LinkedList<DBIndex>();
      oPrimaryKeys = new LinkedList<String>();

      if (DebugFile.trace)
        {
        DebugFile.writeln("Begin DBTable.readColumns([DatabaseMetaData])" );
        DebugFile.incIdent();

        DebugFile.writeln("DatabaseMetaData.getColumns(" + sCatalog + "," + sSchema + "," + sName + ",%)");
        }

      if (oConn.getMetaData().getDatabaseProductName().equals("PostgreSQL"))
        iDBMS = JDCConnection.DBMS_POSTGRESQL;
      else if (oConn.getMetaData().getDatabaseProductName().equals("Oracle"))
        iDBMS = JDCConnection.DBMS_ORACLE;
      else if (oConn.getMetaData().getDatabaseProductName().equals("MySQL"))
        iDBMS = JDCConnection.DBMS_MYSQL;
      else if (oConn.getMetaData().getDatabaseProductName().equals("ACCESS"))
        iDBMS = JDCConnection.DBMS_ACCESS;
      else if (oConn.getMetaData().getDatabaseProductName().equals("Microsoft SQL Server"))
        iDBMS = JDCConnection.DBMS_MSSQL;
      else if (oConn.getMetaData().getDatabaseProductName().equals("SQLite"))
        iDBMS = JDCConnection.DBMS_SQLITE;
      else
        iDBMS = 0;

      oStmt = oConn.createStatement();

      try {
        if (DebugFile.trace) DebugFile.writeln("Statement.executeQuery(SELECT * FROM " + sName + " WHERE 1=0)");

        oRSet = oStmt.executeQuery("SELECT * FROM " + sName + " WHERE 1=0");
        iErrCode = 0;
      }
      catch (SQLException sqle) {
        // Patch for Oracle. DatabaseMetadata.getTables() returns table names
        // that later cannot be SELECTed, so this catch ignore these system tables

        oStmt.close();
        oRSet = null;

        if (DebugFile.trace) DebugFile.writeln("SQLException " + sName + " " + sqle.getMessage());

        iErrCode = sqle.getErrorCode();
        if (iErrCode==0) iErrCode=-1;
        if (!sqle.getSQLState().equals("42000"))
          throw new SQLException(sqle.getMessage(), sqle.getSQLState(), sqle.getErrorCode());
      }

      if (0==iErrCode) {
        if (DebugFile.trace) DebugFile.writeln("ResultSet.getMetaData()");

        oRData= oRSet.getMetaData();

        iCols = oRData.getColumnCount();

        if (DebugFile.trace) DebugFile.writeln("table has " + String.valueOf(iCols) + " columns");

        for (int c=1; c<=iCols; c++) {
          sColName = oRData.getColumnName(c).toLowerCase();
          sTypeName = oRData.getColumnTypeName(c);
          iSQLType = (short) oRData.getColumnType(c);

          if (iDBMS==JDCConnection.DBMS_POSTGRESQL)
            switch (iSQLType) {
              case Types.CHAR:
              case Types.VARCHAR:
                iPrecision = oRData.getColumnDisplaySize(c);
                break;
              default:
                iPrecision = oRData.getPrecision(c);
            }
          else {
            // New for v2.0, solves bug SF887614
            if (iSQLType==Types.BLOB || iSQLType==Types.CLOB)
              iPrecision = 2147483647;
            // end v2.0
            else
              iPrecision = oRData.getPrecision(c);
          }

          iDigits = oRData.getScale(c);
          iNullable = oRData.isNullable(c);
          iColPos = c;

          if (5==iDBMS && iSQLType==Types.NUMERIC && iPrecision<=6 && iDigits==0) {
            // Workaround for an Oracle 9i bug witch is unable to convert from Short to NUMERIC but does understand SMALLINT
            oCol = new DBColumn (sName,sColName,(short) Types.SMALLINT, sTypeName, iPrecision, iDigits, iNullable,iColPos);
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.