java.sql.PreparedStatement ps = null;
java.sql.ResultSet rs = null;
java.sql.Connection connection = null;
javax.sql.DataSource datasource = null;
String dataSourceName = "jdbc/operationsDB";
String roleName = "TestRole";
String sqlQuery = "select RTRIM(XMLAGG(XMLELEMENT(E,usr.usr_login,'|').EXTRACT('//text()') ORDER BY usr.usr_login).GetClobVal(),'|') AS MEMBERS from UGP,USG,USR where USG.UGP_KEY = UGP.UGP_KEY AND USG.USR_KEY = USR.USR_KEY AND UGP_NAME = '" + roleName + "'";
try{
addAuditTrailEntry( "****** Get comma separated member's user login for role *******");
javax.naming.InitialContext initialcontext = new javax.naming.InitialContext();
datasource = (javax.sql.DataSource) initialcontext.lookup(dataSourceName);
if(null != datasource){
connection = datasource.getConnection();
ps = connection.prepareStatement(sqlQuery);
rs = ps.executeQuery();
while(rs.next()){
System.out.println("Role Members : " + rs.getString("MEMBERS"));
addAuditTrailEntry("Role Members : " + rs.getString("MEMBERS"));
}
}else{
System.out.println("Error while getting datasource from JNDI");
}
}catch(Exception e){
System.out.println("********Error******");
System.out.println("Exception : " + e.getMessage());
addAuditTrailEntry("Exception : " + e.getMessage());
}finally{
if (rs != null) {
try {
rs.close();
rs = null;
} catch (java.sql.SQLException e) {
System.out.println("Exception while closing ResultSet : " + e.getMessage());
}
}
if (ps != null) {
try {
ps.close();
ps = null;
} catch (java.sql.SQLException e) {
System.out.println("Exception while closing PreparedStatement : " + e.getMessage());
}
}
if (connection != null) {
try {
connection.close();
connection = null;
} catch (java.sql.SQLException e) {
System.out.println("Exception while closing Connection : " + e.getMessage());
}
}
}
No comments:
Post a Comment