Example usage for java.sql ResultSet getInt

List of usage examples for java.sql ResultSet getInt

Introduction

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

Prototype

int getInt(String columnLabel) throws SQLException;

Source Link

Document

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

Usage

From source file:PooledConnectionExample.java

private static void printEmployee(ResultSet resultSet) throws SQLException {
    System.out.print(resultSet.getInt("employee_id"));
    System.out.print(", ");
    System.out.print(resultSet.getString("last_name"));
    System.out.print(", ");
    System.out.print(resultSet.getString("first_name"));
    System.out.print(", ");
    System.out.println(resultSet.getString("email"));
}

From source file:UpdateableRs.java

public static void printRs(ResultSet rs) throws SQLException {
    rs.beforeFirst();//from   w ww .j  ava  2s.  c o  m

    while (rs.next()) {
        int ssn = rs.getInt("ssn");
        String name = rs.getString("name");
        double salary = rs.getDouble("salary");

        System.out.print("Row Number=" + rs.getRow());
        System.out.print(", SSN: " + ssn);
        System.out.print(", Name: " + name);
        System.out.println(", Salary: $" + salary);
    }
    System.out.println();
}

From source file:ExecuteMethod.java

public static void processExecute(Statement stmt, boolean executeResult) throws SQLException {
    if (!executeResult) {
        int updateCount = stmt.getUpdateCount();
        System.out.println(updateCount + " row was " + "inserted into Employee table.");

    } else {/*w  ww .  j av a  2 s  . c o m*/
        ResultSet rs = stmt.getResultSet();
        while (rs.next()) {
            System.out.println(rs.getInt("SSN") + rs.getString("Name") + rs.getDouble("Salary")
                    + rs.getDate("Hiredate") + rs.getInt("Loc_id"));

        }
    }
}

From source file:com.dbconnection.DataSourceConnection.java

private static String query(Connection connection) throws SQLException {

    String query = "";
    Statement statement = connection.createStatement();

    ResultSet resultSet = statement.executeQuery("SELECT * FROM BOOK");

    while (resultSet.next()) {
        int id = resultSet.getInt("id");
        String title = resultSet.getString("title");

        query = query + id + "\t" + title + "\n";
    }//  www  . ja va  2s.c  om
    return query;
}

From source file:Main.java

public static long writeJavaObject(Connection conn, Object object) throws Exception {
    String className = object.getClass().getName();
    PreparedStatement pstmt = conn.prepareStatement(WRITE_OBJECT_SQL);
    pstmt.setString(1, className);//from  w  w w.  j a v a 2 s .  co m
    pstmt.setObject(2, object);
    pstmt.executeUpdate();
    ResultSet rs = pstmt.getGeneratedKeys();
    int id = -1;
    if (rs.next()) {
        id = rs.getInt(1);
    }
    rs.close();
    pstmt.close();
    return id;
}

From source file:SerializeJavaObjects_MySQL.java

public static long writeJavaObject(Connection conn, Object object) throws Exception {
    String className = object.getClass().getName();
    PreparedStatement pstmt = conn.prepareStatement(WRITE_OBJECT_SQL);

    // set input parameters
    pstmt.setString(1, className);//from   w w  w  .ja v a  2 s . com
    pstmt.setObject(2, object);
    pstmt.executeUpdate();

    // get the generated key for the id
    ResultSet rs = pstmt.getGeneratedKeys();
    int id = -1;
    if (rs.next()) {
        id = rs.getInt(1);
    }

    rs.close();
    pstmt.close();
    System.out.println("writeJavaObject: done serializing: " + className);
    return id;
}

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.espertech.esperio.db.core.DBUtil.java

/**
 * Returns the object value for a given column and type.
 * @param rs result set//from  w ww. ja  v a 2  s.c om
 * @param index column index
 * @param valueType value type
 * @return object value
 * @throws java.sql.SQLException if the column could not be read
 */
public static Object getValue(ResultSet rs, int index, int valueType) throws SQLException {
    if (valueType == Types.INTEGER) {
        return rs.getInt(index);
    } else if (valueType == Types.BIGINT) {
        return rs.getLong(index);
    } else if (valueType == Types.BLOB) {
        Blob blob = rs.getBlob(index);
        return getBlobValue(blob);
    }
    return rs.getObject(index);
}

From source file:de.thejeterlp.bukkit.login.SQLAccount.java

protected static Account convert(UUID uuid) throws SQLException {
    checkReflection();/*w  ww . j a  va 2 s . co m*/
    Validate.notNull(uuid, "uuid cannot be null!");
    PreparedStatement st = Login.getInstance().getDB()
            .getPreparedStatement("SELECT * FROM `" + Statics.USER_TABLE + "` WHERE `uuid` = ? LIMIT 1;");
    st.setString(1, uuid.toString());
    ResultSet rs = st.executeQuery();
    while (rs.next()) {
        int id = rs.getInt("id");
        Login.getInstance().getDB().closeResultSet(rs);
        Login.getInstance().getDB().closeStatement(st);
        PreparedStatement sta = Login.getInstance().getDB().getPreparedStatement(
                "SELECT * FROM `" + Statics.PASSWORD_TABLE + "` WHERE `userID` = ? LIMIT 1;");
        sta.setInt(1, id);
        ResultSet rset = sta.executeQuery();
        while (rset.next()) {
            String hash = rset.getString("password");
            Login.getInstance().getDB().closeResultSet(rset);
            Login.getInstance().getDB().closeStatement(sta);
            return new Account(id, uuid, hash);
        }
    }
    return null;
}

From source file:com.afforess.nsdump.Test.java

public static void testRegionDump() throws IOException, SQLException {
    RegionsDump dump = new RegionsDump();
    dump.parse();/*w  ww .ja v a2 s  .  c  o m*/

    Connection conn = dump.getDatabaseConnection();
    PreparedStatement statement = conn.prepareStatement("SELECT (numnations) FROM regions");
    ResultSet result = statement.executeQuery();
    int total = 0, regions = 0;
    while (result.next()) {
        total += result.getInt(1);
        regions++;
    }
    System.out.println("Total nations: " + total);
    System.out.println("Total regions: " + regions);
    result.close();
    conn.close();

    File db = new File("./ns-db.h2.db");
    db.delete();
}