Example usage for java.sql ResultSet getString

List of usage examples for java.sql ResultSet getString

Introduction

In this page you can find the example usage for java.sql ResultSet getString.

Prototype

String getString(String columnLabel) throws SQLException;

Source Link

Document

Retrieves the value of the designated column in the current row of this ResultSet object as a String in the Java programming language.

Usage

From source file:com.buddycloud.friendfinder.HashUtils.java

public static String retrieveJid(String hash, ComponentDataSource dataSource) {
    PreparedStatement statement = null;
    try {/*  w w  w  . ja v a 2 s  .  c  o m*/
        statement = dataSource
                .prepareStatement("SELECT \"jid\" FROM \"contact-matches\" WHERE \"credential-hash\"=?", hash);
        ResultSet resultSet = statement.executeQuery();
        if (resultSet.next()) {
            return resultSet.getString(1);
        }
        return null;
    } catch (SQLException e) {
        LOGGER.error("Could not retrieve jid from hash " + hash, e);
        throw new RuntimeException(e);
    } finally {
        ComponentDataSource.close(statement);
    }
}

From source file:com.sap.dirigible.repository.db.dao.DBMapper.java

/**
 * ResultSet current row to Content transformation
 * /*from ww  w  .j  a v  a 2s.  c o m*/
 * @param repository
 * @param resultSet
 * @return
 * @throws SQLException
 */
static byte[] dbToData(DBRepository repository, ResultSet resultSet) throws SQLException {
    String data = resultSet.getString("DOC_CONTENT"); //$NON-NLS-1$
    return data.getBytes(Charset.defaultCharset());
}

From source file:org.spc.ofp.data.Repository.java

public static Date readDate(final ResultSet rs, final String columnName) throws SQLException {
    final String dateValue = rs.getString(columnName);
    if (null == dateValue || "".equalsIgnoreCase(dateValue.trim())) {
        return null;
    }// www  . j a v a2s . c om
    Date dt = null;
    try {
        synchronized (SQLITE_DATE_FORMAT) {
            dt = SQLITE_DATE_FORMAT.parse(dateValue);
        }
    } catch (ParseException ignoreMe) {
    } // NOPMD
    return dt;
}

From source file:org.spc.ofp.data.Repository.java

public static Date readTimestamp(final ResultSet rs, final String columnName) throws SQLException {
    final String dateValue = rs.getString(columnName);
    if (null == dateValue || "".equalsIgnoreCase(dateValue.trim())) {
        return null;
    }//ww w .j a  v  a 2 s  .  com
    if (dateValue.trim().startsWith("-4")) {
        return null;
    } // Some of the data has timestamps that go back to 4712 BC
    Date dt = null;
    try {
        synchronized (SQLITE_TIMESTAMP_FORMAT) {
            dt = SQLITE_TIMESTAMP_FORMAT.parse(dateValue);
        }
    } catch (ParseException ignoreMe) {
    } // NOPMD
    return dt;
}

From source file:de.dominikschadow.javasecurity.services.ContactService.java

private static Contact createContact(ResultSet rs) throws SQLException {
    Contact contact = new Contact();
    contact.setId(rs.getInt("id"));
    contact.setUsername(rs.getString("username"));
    contact.setFirstname(rs.getString("firstname"));
    contact.setLastname(rs.getString("lastname"));
    contact.setComment(rs.getString("comment"));
    return contact;
}

From source file:com.us.test.H2Helper.java

public static void main2(String... args) throws Exception {
    createOrUpdate("jdbc:h2:~/data/iph2db", "sa", "sa");
    laodData2H2Db(new File("C:\\Documents and Settings\\Administrator\\data\\ips.txt"), "jdbc:h2:~/data/iph2db",
            "sa", "sa");
    JdbcConnectionPool cp = JdbcConnectionPool.create("jdbc:h2:~/data/iph2db", "sa", "sa");
    Connection conn = cp.getConnection();
    ResultSet rs = conn.createStatement().executeQuery("select * from ips");
    while (rs.next()) {
        System.out.println(/*w  w  w  .  j  a  v  a 2 s .  c  o m*/
                rs.getString(1) + ":" + rs.getString(2) + ":" + rs.getString(3) + ":" + rs.getString(4));
    }

}

From source file:com.firewallid.util.FISQL.java

public static String getFirstFieldInsertIfNotExist(Connection conn, String tableName, String field,
        Map<String, String> fields) throws SQLException {
    /* Query *//*from   w  ww .j a  va 2 s .c  om*/
    String query = "SELECT " + field + " FROM " + tableName + " WHERE "
            + Joiner.on(" = ? AND ").join(fields.keySet()) + " = ?";

    /* Execute */
    PreparedStatement pst = conn.prepareStatement(query);
    int i = 1;
    for (String value : fields.values()) {
        pst.setString(i, value);
        i++;
    }
    ResultSet executeQuery = pst.executeQuery();
    if (executeQuery.next()) {
        return executeQuery.getString(field);
    }

    /* Row is not exists. Insert */
    query = "INSERT INTO " + tableName + " (" + Joiner.on(", ").join(fields.keySet()) + ") VALUES ("
            + StringUtils.repeat("?, ", fields.size() - 1) + "?)";
    pst = conn.prepareStatement(query);
    i = 1;
    for (String value : fields.values()) {
        pst.setString(i, value);
        i++;
    }
    if (pst.execute()) {
        return null;
    }
    return getFirstFieldInsertIfNotExist(conn, tableName, field, fields);
}

From source file:Student.java

  public static void checkData() throws Exception {
  Class.forName("org.hsqldb.jdbcDriver");
  Connection conn = DriverManager.getConnection("jdbc:hsqldb:data/tutorial", "sa", "");
  Statement st = conn.createStatement();

  ResultSet mrs = conn.getMetaData().getTables(null, null, null, new String[] { "TABLE" });
  while (mrs.next()) {
    String tableName = mrs.getString(3);
    System.out.println("\n\n\n\nTable Name: "+ tableName);

    ResultSet rs = st.executeQuery("select * from " + tableName);
    ResultSetMetaData metadata = rs.getMetaData();
    while (rs.next()) {
      System.out.println(" Row:");
      for (int i = 0; i < metadata.getColumnCount(); i++) {
        System.out.println("    Column Name: "+ metadata.getColumnLabel(i + 1)+ ",  ");
        System.out.println("    Column Type: "+ metadata.getColumnTypeName(i + 1)+ ":  ");
        Object value = rs.getObject(i + 1);
        System.out.println("    Column Value: "+value+"\n");
      }/*from  ww  w.  ja v a  2  s  .  c o m*/
    }
  }
}

From source file:com.hs.mail.imap.dao.FlagUtils.java

static Flags getFlags(ResultSet rs) throws SQLException {
    Flags flags = new Flags();
    for (int i = 0; i < attrArray.length; i++) {
        if ("Y".equals(rs.getString(attrArray[i]))) {
            flags.add(flagArray[i]);//  w  ww  .  j  a  va2 s  .  co  m
        }
    }
    return flags;
}

From source file:common.utility.ChartHelper.java

public static CategoryDataset createDataset() throws SQLException {

    // create the dataset...
    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    ResultSet rs = new PersonDetailsDAO().selectAllPersonofArea();
    while (rs.next()) {
        dataset.setValue(rs.getDouble("NumOfCitizens"), "Area Code : " + rs.getString("AreaCode"), "Areas");
    }//from  www  .  jav a2  s.c o m

    return dataset;

}