get Single Result from ResultSet - Java java.sql

Java examples for java.sql:ResultSet

Description

get Single Result from ResultSet

Demo Code


//package com.java2s;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class Main {
    public static Integer getSingleResult(PreparedStatement ps)
            throws SQLException {
        Integer retval;/*from  w  ww . j  a va2s. c o  m*/
        ResultSet rs = ps.executeQuery();
        if (rs.next())
            retval = rs.getInt(1);
        else
            retval = null;
        rs.close();
        return retval;
    }
}

Related Tutorials