Hey,
Did you guys happen to use new java class in 8.5.3. It is awesome. I feel with the introduction of this new java class we need not have to use Lotus script any more for complex operations in Xpages. Earlier for connecting to RDBMS, Crystal reports, generating PDFs on fly we had to call a agent from Xpage and some time use Lotus script or Java agents to perform them and we did not have that must control on refreshing the page such as partial refresh.
Now it all happens seamlessly, I happen to use Xpage code which uses Java class. And Java class in turn connects to oracle database and updates the database database. I used JDBC driver and it works like a charm. Below is the code snippet
Server Side Java script. which takes the value from the front end web page and passes the values to the java class.
function UPDATEASMPARABRIDGES(){
var docID = getComponent("E_DocumentID").getValue();
var ASM_PARA_BRDG_VALUE = getComponent("E_ASM_PARA_BRDG_VALUE").getValue();
var ASM_PARA_BRDG_DESC = getComponent("E_ASM_PARA_BRDG_DESC").getValue();
var currDB:NotesDatabase = session.getCurrentDatabase();
var LkAssetPLOraVW:NotesView = currDB.getView("LkAssetPLOraVW");
var LKDocument:NotesDocument = LkAssetPLOraVW.getDocumentByKey(docID , true);
if(LKDocument != null){
LKDocument.replaceItemValue("ASM_PARA_BRDG_VALUE", ASM_PARA_BRDG_VALUE);
LKDocument.replaceItemValue("ASM_PARA_BRDG_DESC", ASM_PARA_BRDG_DESC);
LKDocument.save(true , false)
var dbConnection = new com.penndot.lpn.DatabaseConnection();
var tableKey = @Text(LKDocument.getItemValueInteger("ASM_PARA_BRDG_ID"));
dbConnection.mainUpdateAsmParaBridges(session,tableKey , @Text(ASM_PARA_BRDG_VALUE),@Text(ASM_PARA_BRDG_DESC))
}
}
And Java class had the following code..
public class DatabaseConnection extends NotesThread{
public static void mainUpdateAsmParaBridges(Session session, String tableKey , String value1 , String value2) throws ClassNotFoundException, SQLException{
try{
Connection conn = getDatbaseConnection(session);
String sqlStatement = "UPDATE ASM_PARA_BRIDGES SET ASM_PARA_BRDG_VALUE='" + value1 + "',asm_para_brdg_desc = '" + value2 + "' WHERE ASM_PARA_BRDG_ID = " + tableKey;
executeQuery(conn , sqlStatement);
closeDatabaseConnection(conn);
}catch (Exception e){
e.printStackTrace();
}
}
public static void mainUpdateAsmParaPavements(Session session, String tableKey , String value1 , String value2) throws ClassNotFoundException, SQLException{
try{
Connection conn = getDatbaseConnection(session);
String sqlStatement = "UPDATE ASM_PARA_PAVEMENTS SET ASM_PARA_PAVE_VALUE = '" + value1 + "',ASM_PARA_PAVE_DESC = '" + value2 + "' WHERE ASM_PARA_PAVE_ID = " + tableKey;
executeQuery(conn , sqlStatement);
closeDatabaseConnection(conn);
}catch (Exception e){
e.printStackTrace();
}
}
public static void mainUpdatePMBridgesParams(Session session, String value0 , String value1 , String value2) throws ClassNotFoundException, SQLException{
try{
Connection conn = getDatbaseConnection(session);
String sqlStatement = "UPDATE PM_BRIDGES_PARAMS SET PARAM_VALUE = '" + value2 + "' WHERE business_plan_network = '" + value0 + "' and param_name = '" + value1 + "'";
executeQuery(conn , sqlStatement);
closeDatabaseConnection(conn);
}catch (Exception e){
e.printStackTrace();
}
}
private static Connection getDatbaseConnection(Session session) throws ClassNotFoundException,SQLException{
Connection conn = null;
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
String url = getKeywordValue(session , "oracleConnectionURL" , "vwKWLU");
String userID = getKeywordValue(session , "oracleUserID" , "vwKWLU");
String pwd = getKeywordValue(session , "oraclePassword" , "vwKWLU");
conn = DriverManager.getConnection(url,userID, pwd);
return conn;
}catch (Exception e){
e.printStackTrace();
return conn;
}
}
private static void executeQuery(Connection conn , String sqlStatement) throws ClassNotFoundException,SQLException{
try{
Statement stmt = conn.createStatement();
stmt.executeQuery(sqlStatement);
}catch (Exception e){
e.printStackTrace();
}
}
private static void closeDatabaseConnection(Connection conn) throws ClassNotFoundException,SQLException{
try{
conn.close();
}catch (Exception e){
e.printStackTrace();
}
}
private static String getKeywordValue(Session session,String keyName , String viewName){
try{
String keywordValue = "";
Database currDatabase = session.getCurrentDatabase();
View keywordView = currDatabase.getView(viewName);
Document keywordDocument = keywordView.getDocumentByKey(keyName , true);
if(keywordDocument != null){
keywordValue= keywordDocument.getItemValueString("ValueTX");
}
return keywordValue;
}catch (Exception e){
e.printStackTrace();
return "";
}
}
}
Did you guys happen to use new java class in 8.5.3. It is awesome. I feel with the introduction of this new java class we need not have to use Lotus script any more for complex operations in Xpages. Earlier for connecting to RDBMS, Crystal reports, generating PDFs on fly we had to call a agent from Xpage and some time use Lotus script or Java agents to perform them and we did not have that must control on refreshing the page such as partial refresh.
Now it all happens seamlessly, I happen to use Xpage code which uses Java class. And Java class in turn connects to oracle database and updates the database database. I used JDBC driver and it works like a charm. Below is the code snippet
Server Side Java script. which takes the value from the front end web page and passes the values to the java class.
function UPDATEASMPARABRIDGES(){
var docID = getComponent("E_DocumentID").getValue();
var ASM_PARA_BRDG_VALUE = getComponent("E_ASM_PARA_BRDG_VALUE").getValue();
var ASM_PARA_BRDG_DESC = getComponent("E_ASM_PARA_BRDG_DESC").getValue();
var currDB:NotesDatabase = session.getCurrentDatabase();
var LkAssetPLOraVW:NotesView = currDB.getView("LkAssetPLOraVW");
var LKDocument:NotesDocument = LkAssetPLOraVW.getDocumentByKey(docID , true);
if(LKDocument != null){
LKDocument.replaceItemValue("ASM_PARA_BRDG_VALUE", ASM_PARA_BRDG_VALUE);
LKDocument.replaceItemValue("ASM_PARA_BRDG_DESC", ASM_PARA_BRDG_DESC);
LKDocument.save(true , false)
var dbConnection = new com.penndot.lpn.DatabaseConnection();
var tableKey = @Text(LKDocument.getItemValueInteger("ASM_PARA_BRDG_ID"));
dbConnection.mainUpdateAsmParaBridges(session,tableKey , @Text(ASM_PARA_BRDG_VALUE),@Text(ASM_PARA_BRDG_DESC))
}
}
And Java class had the following code..
public class DatabaseConnection extends NotesThread{
public static void mainUpdateAsmParaBridges(Session session, String tableKey , String value1 , String value2) throws ClassNotFoundException, SQLException{
try{
Connection conn = getDatbaseConnection(session);
String sqlStatement = "UPDATE ASM_PARA_BRIDGES SET ASM_PARA_BRDG_VALUE='" + value1 + "',asm_para_brdg_desc = '" + value2 + "' WHERE ASM_PARA_BRDG_ID = " + tableKey;
executeQuery(conn , sqlStatement);
closeDatabaseConnection(conn);
}catch (Exception e){
e.printStackTrace();
}
}
public static void mainUpdateAsmParaPavements(Session session, String tableKey , String value1 , String value2) throws ClassNotFoundException, SQLException{
try{
Connection conn = getDatbaseConnection(session);
String sqlStatement = "UPDATE ASM_PARA_PAVEMENTS SET ASM_PARA_PAVE_VALUE = '" + value1 + "',ASM_PARA_PAVE_DESC = '" + value2 + "' WHERE ASM_PARA_PAVE_ID = " + tableKey;
executeQuery(conn , sqlStatement);
closeDatabaseConnection(conn);
}catch (Exception e){
e.printStackTrace();
}
}
public static void mainUpdatePMBridgesParams(Session session, String value0 , String value1 , String value2) throws ClassNotFoundException, SQLException{
try{
Connection conn = getDatbaseConnection(session);
String sqlStatement = "UPDATE PM_BRIDGES_PARAMS SET PARAM_VALUE = '" + value2 + "' WHERE business_plan_network = '" + value0 + "' and param_name = '" + value1 + "'";
executeQuery(conn , sqlStatement);
closeDatabaseConnection(conn);
}catch (Exception e){
e.printStackTrace();
}
}
private static Connection getDatbaseConnection(Session session) throws ClassNotFoundException,SQLException{
Connection conn = null;
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
String url = getKeywordValue(session , "oracleConnectionURL" , "vwKWLU");
String userID = getKeywordValue(session , "oracleUserID" , "vwKWLU");
String pwd = getKeywordValue(session , "oraclePassword" , "vwKWLU");
conn = DriverManager.getConnection(url,userID, pwd);
return conn;
}catch (Exception e){
e.printStackTrace();
return conn;
}
}
private static void executeQuery(Connection conn , String sqlStatement) throws ClassNotFoundException,SQLException{
try{
Statement stmt = conn.createStatement();
stmt.executeQuery(sqlStatement);
}catch (Exception e){
e.printStackTrace();
}
}
private static void closeDatabaseConnection(Connection conn) throws ClassNotFoundException,SQLException{
try{
conn.close();
}catch (Exception e){
e.printStackTrace();
}
}
private static String getKeywordValue(Session session,String keyName , String viewName){
try{
String keywordValue = "";
Database currDatabase = session.getCurrentDatabase();
View keywordView = currDatabase.getView(viewName);
Document keywordDocument = keywordView.getDocumentByKey(keyName , true);
if(keywordDocument != null){
keywordValue= keywordDocument.getItemValueString("ValueTX");
}
return keywordValue;
}catch (Exception e){
e.printStackTrace();
return "";
}
}
}