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;
}
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;
}
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);
}
}
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);
}
}
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;
}
Aggregations