Search in sources :

Example 61 with ResultSet

use of java.sql.ResultSet in project head by mifos.

the class Upgrade method addLookupEntity.

@SuppressWarnings("PMD.CloseResource")
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = { "OBL_UNSATISFIED_OBLIGATION" }, justification = "The statement is closed.")
protected int addLookupEntity(Connection connection, String name, String description) throws SQLException {
    int newId = -1;
    PreparedStatement statement = connection.prepareStatement("insert into lookup_entity(entity_id,entity_name,description) values(null,?,?)", PreparedStatement.RETURN_GENERATED_KEYS);
    statement.setString(1, name);
    statement.setString(2, description);
    statement.executeUpdate();
    ResultSet keys = statement.getGeneratedKeys();
    keys.next();
    newId = Integer.parseInt(keys.getString(1));
    statement.close();
    return newId;
}
Also used : ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 62 with ResultSet

use of java.sql.ResultSet in project head by mifos.

the class ReportsParamQueryDAO method listValuesOfParameters.

/**
     * This method lists all the values of parameter
     */
public List listValuesOfParameters(ReportsParams rps) throws Exception {
    List<ReportsParamQuery> alValues = new ArrayList();
    ReportsDataSource rds = rps.getReportsDataSource();
    Connection con = null;
    try {
        String driver = rds.getDriver();
        String url = rds.getUrl();
        String username = rds.getUsername();
        String password = rds.getPassword();
        if (driver != null && !driver.equals("")) {
            Class.forName(driver);
            con = DriverManager.getConnection(url, username, password);
            Statement stm = con.createStatement();
            String data = rps.getData();
            if (data != null && !data.equals("")) {
                ResultSet rs = stm.executeQuery(data);
                ResultSetMetaData rsmd = rs.getMetaData();
                while (rs.next()) {
                    ReportsParamQuery obj = new ReportsParamQuery();
                    if (rsmd.getColumnCount() >= 2) {
                        obj.setValue1(rs.getString(1));
                        obj.setValue2(rs.getString(2));
                    } else if (rsmd.getColumnCount() == 1) {
                        obj.setValue1(rs.getString(1));
                        obj.setValue2(rs.getString(1));
                    }
                    alValues.add(obj);
                }
            }
        }
    } finally {
        try {
            if (con != null) {
                con.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return alValues;
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) Statement(java.sql.Statement) ArrayList(java.util.ArrayList) ReportsParamQuery(org.mifos.reports.business.ReportsParamQuery) ReportsDataSource(org.mifos.reports.business.ReportsDataSource) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet)

Example 63 with ResultSet

use of java.sql.ResultSet in project Openfire by igniterealtime.

the class Bookmark method loadFromDb.

/**
     * Loads a bookmark from the database.
     *
     * @throws NotFoundException if the bookmark could not be loaded.
     */
private void loadFromDb() throws NotFoundException {
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        con = DbConnectionManager.getConnection();
        pstmt = con.prepareStatement(LOAD_BOOKMARK);
        pstmt.setLong(1, bookmarkID);
        rs = pstmt.executeQuery();
        if (!rs.next()) {
            throw new NotFoundException("Bookmark not found: " + bookmarkID);
        }
        this.type = Type.valueOf(rs.getString(1));
        this.name = rs.getString(2);
        this.value = rs.getString(3);
        this.global = rs.getInt(4) == 1;
        rs.close();
        pstmt.close();
    } catch (SQLException sqle) {
        Log.error(sqle.getMessage(), sqle);
    } finally {
        DbConnectionManager.closeConnection(rs, pstmt, con);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) NotFoundException(org.jivesoftware.util.NotFoundException) PreparedStatement(java.sql.PreparedStatement)

Example 64 with ResultSet

use of java.sql.ResultSet in project Openfire by igniterealtime.

the class PseudoRoster method loadFromDb.

/**
     * Load pseudo roster from database.
     */
private void loadFromDb() {
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        con = DbConnectionManager.getConnection();
        pstmt = con.prepareStatement(GET_ALL_USER_ROSTER_ITEMS);
        pstmt.setLong(1, registrationID);
        rs = pstmt.executeQuery();
        while (rs.next()) {
            String username = rs.getString(1);
            try {
                pseudoRosterItems.put(username, new PseudoRosterItem(registrationID, username));
            } catch (NotFoundException e) {
                Log.error("Could not find pseudo roster item after already having found it.", e);
            }
        }
    } catch (SQLException sqle) {
        Log.error(sqle);
    } finally {
        DbConnectionManager.closeConnection(rs, pstmt, con);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) NotFoundException(org.jivesoftware.util.NotFoundException) PreparedStatement(java.sql.PreparedStatement)

Example 65 with ResultSet

use of java.sql.ResultSet in project Openfire by igniterealtime.

the class PermissionManager method getAllGroups.

/**
     * Retrieves a list of all of the groups permitted to access this transport.
     *
     * @return List of groups (as strings)
     */
public ArrayList<String> getAllGroups() {
    ArrayList<String> groupList = new ArrayList<String>();
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        con = DbConnectionManager.getConnection();
        pstmt = con.prepareStatement(GET_ALL_GROUPS);
        pstmt.setString(1, transportType.toString());
        rs = pstmt.executeQuery();
        while (rs.next()) {
            groupList.add(rs.getString(1));
        }
    } catch (SQLException sqle) {
        Log.error(sqle);
    } finally {
        DbConnectionManager.closeConnection(rs, pstmt, con);
    }
    return groupList;
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Aggregations

ResultSet (java.sql.ResultSet)15888 PreparedStatement (java.sql.PreparedStatement)9451 SQLException (java.sql.SQLException)6466 Connection (java.sql.Connection)6445 Statement (java.sql.Statement)4619 Test (org.junit.Test)3647 ArrayList (java.util.ArrayList)2376 Properties (java.util.Properties)1233 HashMap (java.util.HashMap)639 ResultSetMetaData (java.sql.ResultSetMetaData)620 CallableStatement (java.sql.CallableStatement)580 DatabaseMetaData (java.sql.DatabaseMetaData)499 IOException (java.io.IOException)438 List (java.util.List)433 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)414 Timestamp (java.sql.Timestamp)363 Map (java.util.Map)359 BigDecimal (java.math.BigDecimal)350 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)292 HashSet (java.util.HashSet)247