Example usage for java.sql ResultSet next

List of usage examples for java.sql ResultSet next

Introduction

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

Prototype

boolean next() throws SQLException;

Source Link

Document

Moves the cursor forward one row from its current position.

Usage

From source file:com.bluepandora.therap.donatelife.service.CheckService.java

public static boolean isMobileNumberTaken(String mobileNumber, DatabaseService dbService) {
    String query = GetQuery.mobileNumberUsedQuery(mobileNumber);
    ResultSet result = dbService.getResultSet(query);
    boolean mobileNumberRegistered = false;
    try {/*w  ww.  j a v a  2  s. c  om*/
        while (result.next()) {
            mobileNumberRegistered = true;
        }
    } catch (SQLException error) {
        Logger.getLogger(CheckService.class.getName()).log(Level.SEVERE, null, error);
    }
    return mobileNumberRegistered;
}

From source file:com.nabla.wapp.server.database.Database.java

public static Integer addRecord(final Connection conn, final String sql, final Object... parameters)
        throws SQLException {
    final PreparedStatement stmt = StatementFormat.prepare(conn, Statement.RETURN_GENERATED_KEYS, sql,
            parameters);//from w ww  . j a  va 2  s.com
    try {
        if (stmt.executeUpdate() != 1) {
            if (log.isErrorEnabled())
                log.error("failed to add record");
            return null;
        }
        final ResultSet rsKey = stmt.getGeneratedKeys();
        try {
            rsKey.next();
            return rsKey.getInt(1);
        } finally {
            rsKey.close();
        }
    } finally {
        stmt.close();
    }
}

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");
                }// ww w. ja  v  a  2s  .  c om
            }
        }
    }

From source file:Main.java

public static Element appendResultSetToNode(Element root, String rowTag, ResultSet rs) throws SQLException {
    Document doc = root.getOwnerDocument();

    ResultSetMetaData meta = rs.getMetaData();
    int columnCount = meta.getColumnCount();
    int rowCount = 0;
    while (rs.next()) {
        Element rowElement = doc.createElement(rowTag);
        rowElement.setAttribute("row", "" + rowCount);
        for (int i = 1; i <= columnCount; i++) {
            rowElement.setAttribute(meta.getColumnName(i), rs.getString(i));
        }// w ww  .ja  va  2 s  .  c  o  m
        rowCount++;
        root.appendChild(rowElement);
    }

    return root;
}

From source file:TestDebug_MySQL.java

public static int countRows(Connection conn, String tableName) throws SQLException {
    Statement stmt = null;/*ww  w  .j av a 2s .c  om*/
    ResultSet rs = null;
    int rowCount = -1;
    try {
        stmt = conn.createStatement();
        rs = stmt.executeQuery("SELECT COUNT(*) FROM " + tableName);
        // get the number of rows from the result set
        rs.next();
        rowCount = rs.getInt(1);
    } finally {
        rs.close();
        stmt.close();
    }

    return rowCount;
}

From source file:CountRows_MySQL.java

public static int countRows(Connection conn, String tableName) throws SQLException {
    // select the number of rows in the table
    Statement stmt = null;//from   w  ww.ja  va2  s.co m
    ResultSet rs = null;
    int rowCount = -1;
    try {
        stmt = conn.createStatement();
        rs = stmt.executeQuery("SELECT COUNT(*) FROM " + tableName);
        // get the number of rows from the result set
        rs.next();
        rowCount = rs.getInt(1);
    } finally {
        rs.close();
        stmt.close();
    }
    return rowCount;
}

From source file:local.Statistics.LessSellRepuesto.java

/**
 * @param args the command line arguments
 *//*from w w  w .j a v  a 2s.c o m*/
public static void repuestosMenosVendidos() {
    Graficas_DAO gr = new Graficas_DAO();
    //obtencion de datos
    ResultSet rs = gr.getgraficarepuestomen();
    try {
        String nameAuto;
        int quantitySales;
        DefaultPieDataset data = new DefaultPieDataset();
        while (rs.next()) {
            nameAuto = rs.getString(3);
            quantitySales = rs.getInt(1);
            data.setValue(nameAuto, quantitySales);
        }
        JFreeChart chart = ChartFactory.createPieChart("GRAFICAS REPUESTO MENOS VENDIDOS", data, true, true,
                false);
        ChartFrame frame = new ChartFrame("Repuestos menos vendidos", chart);
        frame.pack();
        frame.setVisible(true);
        rs.close();
        gr.close();
    } catch (SQLException ex) {
        Logger.getLogger(LessSellRepuesto.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:CountRows_Oracle.java

public static int countRows(Connection conn, String tableName) throws SQLException {
    // select the number of rows in the table
    Statement stmt = null;/*from   w  w w .  j av  a 2s .com*/
    ResultSet rs = null;
    int rowCount = -1;
    try {
        stmt = conn.createStatement();
        rs = stmt.executeQuery("SELECT COUNT(*) FROM " + tableName);
        // get the number of rows from the result set
        rs.next();
        rowCount = rs.getInt(1);
    } finally {
        rs.close();
        stmt.close();
    }

    return rowCount;
}

From source file:com.seventh_root.ld33.common.player.Player.java

public static Player getByName(Connection databaseConnection, String playerName) throws SQLException {
    if (playersByName.containsKey(playerName))
        return playersByName.get(playerName);
    if (databaseConnection != null) {
        PreparedStatement statement = databaseConnection.prepareStatement(
                "SELECT uuid, name, password_hash, password_salt, resources FROM player WHERE name = ? LIMIT 1");
        statement.setString(1, playerName);
        ResultSet resultSet = statement.executeQuery();
        if (resultSet.next()) {
            return new Player(databaseConnection, UUID.fromString(resultSet.getString("uuid")),
                    resultSet.getString("name"), resultSet.getString("password_hash"),
                    resultSet.getString("password_salt"), resultSet.getInt("resources"));
        }// w w w.j av  a2 s  .c  o  m
    }
    return null;
}

From source file:ch.newscron.registration.UserRegistration.java

private static List<User> parseResultSet(ResultSet resultSet) {
    List<User> userList = new ArrayList<>();
    try {/*ww w .j  av  a2s.c  om*/
        while (resultSet.next()) {
            User newUser = new User(resultSet.getString("name"), resultSet.getString("lastName"),
                    resultSet.getString("email"), resultSet.getLong("campaignId"),
                    resultSet.getString("custID"), resultSet.getString("shortURL"));
            userList.add(newUser);
        }
        return userList;
    } catch (SQLException ex) {
        Logger.getLogger(ReferralManager.class.getName()).log(Level.SEVERE, null, ex);
    }

    return null;
}