Greetings! I am pleased to announce that I have successfully resolved the issue at hand.
It has come to my attention that many individuals encounter similar challenges, which is why I have made the decision to disclose my code in hopes of providing assistance.
MFP 7.1 JavaScript SQL Adapter Utilizing Java
function fetchUserDetails(userCode) {
var stream = { close: function () { } };
var userData = {};
var connection = obtainConnection();
var retrieveUserSQL = 'SELECT * FROM DUAL'; // your sql
if(connection !== null && !connection.error) {
try {
var stmt = java.lang.Class.forName("java.sql.PreparedStatement").cast(connection.prepareStatement(retrieveUserSQL));
stmt.setString(1, userCode);
var rs = java.lang.Class.forName("java.sql.ResultSet").cast(stmt.executeQuery());
while(rs.next()) {
userData.name = rs.getString("USER_NAME");
userData.userCode = rs.getString("CODE_USER");
var clob = rs.getClob("AVATAR");
var reader = java.lang.Class.forName("java.io.Reader").cast(clob.getCharacterStream());
var bufferedReader = new java.io.BufferedReader(reader);
var line = '';
while((line = bufferedReader.readLine()) !== null) {
userData.avatar += line;
}
}
return userData;
} catch(error) {
return { error: error };
} finally {
stream.close();
connection.close();
}
}
return { isSuccessful: false, connection: connection };
}
function obtainConnection() {
var connection = null;
try {
var context = new javax.naming.InitialContext();
var dataSource = java.lang.Class.forName("javax.sql.DataSource").cast(context.lookup("YourJNDI"));
connection = java.lang.Class.forName("java.sql.Connection").cast(dataSource.getConnection());
return connection;
} catch(error) {
WL.Logger.warn("Error: " + error);
return {
error: error
};
}
return connection;
}
If anyone has suggestions on how to enhance the code, please feel free to share.
Farewell!