Package java.sql

Examples of java.sql.ResultSet


   */
  public String[] list(String prefix) throws IOException {
    try {
      // Creating a statement lets us issue commands against the connection.
      Statement s = conn.createStatement();
      ResultSet rs = s.executeQuery("SELECT name FROM JoramDB WHERE name LIKE '" + prefix + "%'");

      Vector v = new Vector();
      while (rs.next()) {
        v.add(rs.getString(1));
      }
      rs.close();
      s.close();

      String[] result = new String[v.size()];
      result = (String[]) v.toArray(result);

View Full Code Here


    try {
      // Creating a statement lets us issue commands against the connection.
      Statement s = conn.createStatement();
      //
      ResultSet rs = s.executeQuery("SELECT content FROM JoramDB WHERE name='" + fname + "'");

       if (!rs.next()) {
         throw new FileNotFoundException("Cannot find object in JoramDB " + ("serverCounter".equals(fname)?"[KNOWN PROBLEM] ":"") + fname);
       }

       byte[] content = rs.getBytes(1);

       rs.close();
       s.close();

       if (logger.isLoggable(BasicLevel.DEBUG))
           logger.log(BasicLevel.DEBUG, "load, after database call");
View Full Code Here

                if (!metadata.supportsSchemasInProcedureCalls()) {
                    schema = "";
                }


                ResultSet procNames =
                    metadata.getProcedures(catalog, schema, procName);
                int procFound = 0;
                while (procNames.next()) {
                    procFound++;
                }
                procNames.close();
                if (procFound == 0) {
                    throw new ResourceException("Cannot find procedure " +
                                                procName +
                                                ". Please check catalog, schema and function name.");
                }

    ResultSet rs =
        metadata.getProcedureColumns(catalog,schema,procName,null);
                List parameterList = new ArrayList();
    boolean function=false;
    while(rs.next()) {            
        if((rs.getShort(5)==DatabaseMetaData.procedureColumnReturn)
      && (!((rs.getString(7)).equals("void")))) {
      function= true;       
        }
        if (rs.getString(7).equals("void")) {
                        continue; // skip extra info from Cloudscape
        }
        parameterList.add(new Parameter( rs.getString(1),
                                                     rs.getString(2),
                                                     rs.getString(3),
                                                     rs.getString(4),
                                                     rs.getShort(5),
                                                     rs.getShort(6),
                                                     rs.getShort(10)));
    }
                rs.close();

                int paramCount = parameterList.size();
    if (function) {
                    paramCount -= 1;
                }
View Full Code Here

        try {
          ps = stmt.getConnection().prepareStatement("select attrelid, attnum, typoid from matpg_relatt where attname = ? and relname = ? and nspname = ?");
          ps.setString(1, name);
          ps.setString(2, table);
          ps.setString(3, schema);
          ResultSet rs = ps.executeQuery();
          if (rs.next()) {
            info.reloid = rs.getInt(1);
            info.attnum = rs.getShort(2);
            int specificType = rs.getInt(3);
            if (!rs.wasNull()) {
              info.type = specificType;
            }
          }
        } finally {
          if (ps != null) {
View Full Code Here

              + " rows affected.");
        close();
        return null;
      }
    }
    ResultSet rs = getResultSet();
    if (m_Debug)
      System.err.println("Getting metadata...");
    ResultSetMetaData md = rs.getMetaData();
    if (m_Debug)
      System.err.println("Completed getting metadata...");
   
   
    // Determine structure of the instances
    int numAttributes = md.getColumnCount();
    int [] attributeTypes = new int [numAttributes];
    Hashtable [] nominalIndexes = new Hashtable [numAttributes];
    FastVector [] nominalStrings = new FastVector [numAttributes];
    for (int i = 1; i <= numAttributes; i++) {
      /* switch (md.getColumnType(i)) {
      case Types.CHAR:
      case Types.VARCHAR:
      case Types.LONGVARCHAR:
      case Types.BINARY:
      case Types.VARBINARY:
      case Types.LONGVARBINARY:*/
     
      switch (translateDBColumnType(md.getColumnTypeName(i))) {
 
      case STRING :
  //System.err.println("String --> nominal");
  attributeTypes[i - 1] = Attribute.NOMINAL;
  nominalIndexes[i - 1] = new Hashtable();
  nominalStrings[i - 1] = new FastVector();
  break;
      case TEXT:
  //System.err.println("Text --> string");
  attributeTypes[i - 1] = Attribute.STRING;
  nominalIndexes[i - 1] = new Hashtable();
  nominalStrings[i - 1] = new FastVector();
  break;
      case BOOL:
  //System.err.println("boolean --> nominal");
  attributeTypes[i - 1] = Attribute.NOMINAL;
  nominalIndexes[i - 1] = new Hashtable();
  nominalIndexes[i - 1].put("false", new Double(0));
  nominalIndexes[i - 1].put("true", new Double(1));
  nominalStrings[i - 1] = new FastVector();
  nominalStrings[i - 1].addElement("false");
  nominalStrings[i - 1].addElement("true");
  break;
      case DOUBLE:
  //System.err.println("BigDecimal --> numeric");
  attributeTypes[i - 1] = Attribute.NUMERIC;
  break;
      case BYTE:
  //System.err.println("byte --> numeric");
  attributeTypes[i - 1] = Attribute.NUMERIC;
  break;
      case SHORT:
  //System.err.println("short --> numeric");
  attributeTypes[i - 1] = Attribute.NUMERIC;
  break;
      case INTEGER:
  //System.err.println("int --> numeric");
  attributeTypes[i - 1] = Attribute.NUMERIC;
  break;
      case LONG:
  //System.err.println("long --> numeric");
  attributeTypes[i - 1] = Attribute.NUMERIC;
  break;
      case FLOAT:
  //System.err.println("float --> numeric");
  attributeTypes[i - 1] = Attribute.NUMERIC;
  break;
      case DATE:
  attributeTypes[i - 1] = Attribute.DATE;
  break;
      case TIME:
  attributeTypes[i - 1] = Attribute.DATE;
  break;
      default:
  //System.err.println("Unknown column type");
  attributeTypes[i - 1] = Attribute.STRING;
      }
    }

    // For sqlite
    // cache column names because the last while(rs.next()) { iteration for
    // the tuples below will close the md object: 
    Vector<String> columnNames = new Vector<String>();
    for (int i = 0; i < numAttributes; i++) {
      columnNames.add(md.getColumnLabel(i + 1));
    }

    // Step through the tuples
    if (m_Debug)
      System.err.println("Creating instances...");
    FastVector instances = new FastVector();
    int rowCount = 0;
    while(rs.next()) {
      if (rowCount % 100 == 0) {
        if (m_Debug)  {
    System.err.print("read " + rowCount + " instances \r");
    System.err.flush();
        }
      }
      double[] vals = new double[numAttributes];
      for(int i = 1; i <= numAttributes; i++) {
  /*switch (md.getColumnType(i)) {
  case Types.CHAR:
  case Types.VARCHAR:
  case Types.LONGVARCHAR:
  case Types.BINARY:
  case Types.VARBINARY:
  case Types.LONGVARBINARY:*/
  switch (translateDBColumnType(md.getColumnTypeName(i))) {
  case STRING :
    String str = rs.getString(i);
   
    if (rs.wasNull()) {
      vals[i - 1] = Utils.missingValue();
    } else {
      Double index = (Double)nominalIndexes[i - 1].get(str);
      if (index == null) {
        index = new Double(nominalStrings[i - 1].size());
        nominalIndexes[i - 1].put(str, index);
        nominalStrings[i - 1].addElement(str);
      }
      vals[i - 1] = index.doubleValue();
    }
    break;
  case TEXT:
    String txt = rs.getString(i);
   
    if (rs.wasNull()) {
      vals[i - 1] = Utils.missingValue();
    } else {
      Double index = (Double)nominalIndexes[i - 1].get(txt);
      if (index == null) {
        index = new Double(nominalStrings[i - 1].size());
        nominalIndexes[i - 1].put(txt, index);
        nominalStrings[i - 1].addElement(txt);
      }
      vals[i - 1] = index.doubleValue();
    }
    break;
  case BOOL:
    boolean boo = rs.getBoolean(i);
    if (rs.wasNull()) {
      vals[i - 1] = Utils.missingValue();
    } else {
      vals[i - 1] = (boo ? 1.0 : 0.0);
    }
    break;
  case DOUBLE:
    //    BigDecimal bd = rs.getBigDecimal(i, 4);
    double dd = rs.getDouble(i);
    // Use the column precision instead of 4?
    if (rs.wasNull()) {
      vals[i - 1] = Utils.missingValue();
    } else {
      //      newInst.setValue(i - 1, bd.doubleValue());
      vals[i - 1] =  dd;
    }
    break;
  case BYTE:
    byte by = rs.getByte(i);
    if (rs.wasNull()) {
      vals[i - 1] = Utils.missingValue();
    } else {
      vals[i - 1] = (double)by;
    }
    break;
  case SHORT:
    short sh = rs.getShort(i);
    if (rs.wasNull()) {
      vals[i - 1] = Utils.missingValue();
    } else {
      vals[i - 1] = (double)sh;
    }
    break;
  case INTEGER:
    int in = rs.getInt(i);
    if (rs.wasNull()) {
      vals[i - 1] = Utils.missingValue();
    } else {
      vals[i - 1] = (double)in;
    }
    break;
  case LONG:
    long lo = rs.getLong(i);
    if (rs.wasNull()) {
      vals[i - 1] = Utils.missingValue();
    } else {
      vals[i - 1] = (double)lo;
    }
    break;
  case FLOAT:
    float fl = rs.getFloat(i);
    if (rs.wasNull()) {
      vals[i - 1] = Utils.missingValue();
    } else {
      vals[i - 1] = (double)fl;
    }
    break;
  case DATE:
          Date date = rs.getDate(i);
          if (rs.wasNull()) {
      vals[i - 1] = Utils.missingValue();
    } else {
            // TODO: Do a value check here.
            vals[i - 1] = (double)date.getTime();
          }
          break;
  case TIME:
          Time time = rs.getTime(i);
          if (rs.wasNull()) {
      vals[i - 1] = Utils.missingValue();
    } else {
            // TODO: Do a value check here.
            vals[i - 1] = (double) time.getTime();
          }
View Full Code Here

      statement = m_Connection.createStatement(
    ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
    else
      statement = m_Connection.createStatement(
    getSupportedCursorScrollType(), ResultSet.CONCUR_READ_ONLY);
    ResultSet result = statement.executeQuery(query);
   
    return result;
  }
View Full Code Here

   
    if (m_Debug) {
      System.err.println("Checking if table " + tableName + " exists...");
    }
    DatabaseMetaData dbmd = m_Connection.getMetaData();
    ResultSet rs;
    if (m_checkForUpperCaseNames) {
      rs = dbmd.getTables (null, null, tableName.toUpperCase(), null);
    } else if (m_checkForLowerCaseNames) {
      rs = dbmd.getTables (null, null, tableName.toLowerCase(), null);
    } else {
      rs = dbmd.getTables (null, null, tableName, null);
    }
    boolean tableExists = rs.next();
    if (rs.next()) {
      throw new Exception("This table seems to exist more than once!");
    }
    rs.close();
    if (m_Debug) {
      if (tableExists) {
  System.err.println("... " + tableName + " exists");
      } else {
  System.err.println("... " + tableName + " does not exist");
View Full Code Here

    query += key[i].toString();
  }
      }
    }
    boolean retval = false;
    ResultSet rs = select(query);
    if (rs.next()) {
      retval = true;
      if (rs.next()) {
  throw new Exception("More than one result entry "
      + "for result key: " + query);
      }
    }
    close(rs);
View Full Code Here

  } else {
    query += key[i].toString();
  }
      }
    }
    ResultSet rs = select(query);
    ResultSetMetaData md = rs.getMetaData();
    int numAttributes = md.getColumnCount();
    if (!rs.next()) {
      throw new Exception("No result for query: " + query);
    }
    // Extract the columns for the result
    Object [] result = new Object [numAttributes];
    for(int i = 1; i <= numAttributes; i++) {
      switch (translateDBColumnType(md.getColumnTypeName(i))) {
  case STRING :
    result[i - 1] = rs.getString(i);
    if (rs.wasNull()) {
      result[i - 1] = null;
    }
    break;
  case FLOAT:
  case DOUBLE:
    result[i - 1] = new Double(rs.getDouble(i));
    if (rs.wasNull()) {
      result[i - 1] = null;
    }
    break;
  default:
    throw new Exception("Unhandled SQL result type (field " + (i + 1)
        + "): "
        + DatabaseUtils.typeName(md.getColumnType(i)));
      }
    }
    if (rs.next()) {
      throw new Exception("More than one result entry "
        + "for result key: " + query);
    }
    close(rs);
    return result;
View Full Code Here

     
      //}

    // Get the number of rows
    String query = "SELECT COUNT(*) FROM " + EXP_INDEX_TABLE;
    ResultSet rs = select(query);
    if (m_Debug) {
      System.err.println("...getting number of rows");
    }
    if (rs.next()) {
      numRows = rs.getInt(1);
    }
    close(rs);

    // Add an entry in the index table
    String expType = rp.getClass().getName();
View Full Code Here

TOP

Related Classes of java.sql.ResultSet

Copyright © 2015 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.