How to Retrieve CLOB Data Using MobileFirst 7.1 JavaScript Adapter?

function retrieveUserDetails(userId) {

    var userData = {};

    var queryResult = WL.Server.invokeSQLStatement({
        preparedStatement: getUserSQL,
        parameters: [userId]
    });

    userData = {
       name: queryResult.resultSet[0]['NAME'],
       image: queryResult.resultSet[0]['IMAGE'] // ???
    }

    return userData;
}

When this function is called, it returns clob.toString. Is there a way to extract the string (32K) from CLOB data type?

Answer №1

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!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The excessive offset of pixels is causing the popup dialog to appear misaligned

I'm having an issue with my modal popups where the dialog is rendering 200px to the left and about 100px above its intended position. Just updated jQuery. DevicesRightClickActionsMenuController.prototype.showActionsMenu = function(event) { right ...

Best practices for implementing localization in AngularJS 1.5.x

Visit this link When working with newer versions of the framework (>=1.4.0), it is recommended to utilize the built-in i18n tools. For older versions (<1.4.0), angular-translate is a suitable option. The documentation provides detailed steps for ...

Utilize Laravel 8 and Vue Js to dynamically showcase retrieved data in input fields

I am facing a challenge with my Laravel 8 registration form using Vue js. Before submitting the form, I need to verify if the referring user exists in the database. If the user is found, I want to dynamically display their full name in an input field upon ...

What causes certain images to have unspecified height and width measurements?

Currently, I am in the process of extracting image sizes from a website using a module called scraperjs. Most images have their height and width attributes defined, but some do not, resulting in the returned value being "undefined". How can I retrieve the ...

Vue.js - Difficulty displaying fetched data from API using v-for

My attempt to render a list of data seems to be hitting a roadblock - the data doesn't display when the page loads. The API call works perfectly, fetching all the necessary data and setting it to my data object. Here's the code snippet: once &apo ...

AngularJs, simplifying logic in web pages

I'm currently working with an HTML template that has some complex conditionals in the ng-ifs and ng-shows. For example, here's how I determine if payment controls should be displayed: <div ng-show="ticket.status == 0 && ((ticket.or ...

In Nodejs, the value of req.headers['authorization'] is not defined when using JWT (JSON Web Token)

Below is the implementation of JWT in Node.js: const express = require("express"); const jwt = require("jsonwebtoken"); const app = express(); app.use(express.json()); const user = [ { name: "Rohan", id: 1, }, { name: "Sophie", id ...

Add together the values retrieved from various AJAX calls

I'm attempting to calculate the total value of the data returned by multiple ajax requests. However, I am facing an issue where the total is always showing as 0 because the calculation is happening before the ajax requests are completed. var totalRev ...

Leveraging server-sent events to retrieve an array from a MySQL database using PHP

I've been attempting to implement server-sent events in order to fetch data from a database and dynamically update my HTML page whenever a new message is received. Here's the code I'm using: function update() { if(typeof(Event ...

Flowplayer playlist stops after playing the first clip

I am having issues with my flowplayer configuration, as it is not behaving as I expected. After the first video ends, I want the second and subsequent videos to play automatically. Can anyone provide some guidance on how to achieve this? $f("player", "/fl ...

Selecting meteor.js user logout functionality

Is there a reliable method for detecting when a user logs out of the website? I have some maintenance tasks that need to be handled upon logout. The website is built using meteor.js user accounts. I will also be implementing validation features, so it&apo ...

executing concurrent npm tasks on a Windows operating system

After setting up an npm parallel script in my package.json, I noticed that it works smoothly on a mac but encounters issues when run on windows: "myScript": "nodemon ./server.js & cross-env NODE_ENV=development webpack-dev-server" However, when the s ...

Fetching the appropriate resources to enable the Bootstrap select-picker via AJAX request

I am facing a similar issue like the ones discussed in this post and this one. Despite trying all the suggested solutions in the comments, I have managed to make it work to some extent. My specific problem arises when I choose an option from #main_cat, th ...

The Console.log() function displays the current state and value of a promise object within the Q library

Whenever I attempt to print a promise object from Q, the result that I receive is as follows: var Q = require('q'); var defaultPromise = new Q(); console.log('defaultPromise', defaultPromise); defaultPromise { state: 'fulfilled& ...

Is it possible to create a single code that can be used for various buttons that perform the same function?

Whenever I click the right button, the left button appears and when I reach the last page, the right button disappears. However, this behavior is affecting both sections. Is there a way to write separate code for each section? I managed to make it work by ...

Instructions for positioning a 3d cube within another 3d cube with the help of three.js

I'm currently working on a project involving cargo management and I am looking to create a 3D image of the packing order. I am new to using THREE.js and need assistance in rendering the objects inside the container. While I have the positions (x, y, ...

Stripe.js is frustrated by the duplicate inclusion in the code

Having an issue with Stripe.js - a warning keeps popping up in the console: Seems like Stripe.js has been loaded multiple times. Make sure to only load it once per page. Although the javascript is only present once on the page and the network tab in Dev ...

What makes realtime web programming so fascinating?

Working as a web developer, I have successfully created various real-time collaborative services such as a chat platform by utilizing third-party tools like Redis and Pusher. These services offer straightforward APIs that enable me to establish bidirection ...

Changing input values in AngularJS

Recently, I have been working on developing a grocery list application using AngularJS. I have encountered a specific issue that I need help with. Here is the link to the problem on CodePen. The main problem I am facing is related to the highlighting of C ...

Having difficulty integrating framer-motion with react-router

I've been working on adding animations and smooth transitions to my app using Framer-motion, but I'm facing some challenges in getting it all to function properly. With react-router 6, my goal is to trigger exit animations on route sub-component ...