Using session variables to store connection objects for database rollback

My web application is divided into multiple modules spread across different JSP pages. Currently, I am facing the challenge of using separate oracle connection objects on each page due to scope limitations. The problem arises when I need to rollback database transactions from any of the JSP pages on a central display page with the click of a button. However, database rollback requires a connected connection object.

I am considering a solution where I maintain only one connection object, add it to the list of session variables, and then dereference it as needed. This approach would allow me to rollback database transactions from any page directly from the central display page. I am hopeful that this solution is feasible.

Answer №1

To handle the connection needed, consider creating a singleton class for easy access. A pool could be an option, but a singleton class should suffice. When a rollback is required, retrieve the connection from the class and perform the rollback manually (or delegate the task to the class). If using a pool, loop through the active connections to execute the rollback process.

It's not recommended to open connections within JSP files. It's best to keep the logic separated from the presentation layer. Instantiating classes can be a step in the right direction towards achieving this separation.

Hopefully, these suggestions prove to be helpful.

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

Display the number of likes without having to refresh the page

On my website, there is a like/unlike post feature. When I click the like button, I want the value of check2 to appear next to the like button without needing to refresh the page. Currently, after clicking like, the data is inserted but only appears after ...

Is there a way to convert a PHP array into a JavaScript object and return it?

When I have an array defined and encode it using json_encode() $array = array("a" => "element1", "b" => "element2"); echo json_encode($array); The usual JSON output is: {"a":"element1","b":"element2"} However, my interest lies in getting this out ...

Failed to send JSON parameter to REST API service

I'm experiencing issues when attempting to send an object via POST to my RESTful service built with Spring MVC. On my test page, I have the following code: var obj = { tobj: {id: 1, desc: 'yesh'}}; $.ajax({ url : 'http://localhost ...

AngularJS: Modifying values in one div updates data in all other divs

The webpage appears as shown below: https://i.sstatic.net/IxcnK.png HTML <li class="list-group-item" ng-repeat="eachData in lstRepositoryData"> <div class="ember-view"> <div class="github-connection overflow-hidden shadow-oute ...

Creating a collection of arrays that are named based on the properties of an object

After calling an ajax service, I received a collection of objects where Object (A) properties are Group, order, salary. For example, the objects could be [Employee, 1, 1500],[Management, 2, 2000], [Employee, 3, salary]. My task is to create an array for e ...

Setting up Eclipse for C Programming should not be such a challenging task

As I delve into studying C programming, I found myself facing a dilemma on my Win 7 laptop where I have installed Eclipse-Neon and the latest Java JDK. Despite hours of searching, I couldn't locate the C INCLUDE FILES I needed. The INCLUDE DIRECTORY i ...

Steps to send a prop value to a Vue.js SCSS file

I am trying to include the props (string) value in my scss file Within my component, I am using the nbColor prop with a value of 'warning'. I want to be able to use this value in my scss file where I have a class called .colorNb {color: color(nb ...

Using the result of one function in another function when using async await

I am facing an issue with running a function based on the return value of another function: // in utils.js methods:{ funcOne(){ // do some thing return true } } //in component.vue methods:{ funcTwo(){ let x = this.funcOne() if(x){ ...

AngularJS: Utilizing ellipsis for text overflow and optimization

As a beginner in angularJS, I might have made some mistakes... Can anyone guide me on how to properly implement this plugin: https://github.com/BeSite/jQuery.dotdotdot on my table? Currently, the performance of my edit form and table is very slow. What c ...

Request for removal in Express.js

Currently in the process of developing a MERN-stack app, but encountering issues with the delete request function. Here is the relevant code snippet: Upon attempting to send a delete request via Postman, an error message is displayed. I have researched ...

Combining two forms into one PHP page, but intending to submit only a single form

I'm facing an issue on my page where I have both a sign-in and a sign-up form. Whenever I click on either the sign-in or sign-up button, it always ends up submitting the sign-up form. What am I doing wrong? Here's the PHP code snippet: if($_SE ...

In production, all Next.js API routes consistently return an "Interval Server Error," whereas in development, all routes operate smoothly without any issues

Every time I access any API route in my Next.js application in production, it results in a 500 "Internal Server Error". However, in development mode, all routes function smoothly and provide the expected output. https://i.stack.imgur.com/nPpeV.png https: ...

JavaScript layout: Thymealf

I have a unique thymeleaf template like so: <body> <div id="layout"> <!-- Menu toggle --> <a href="#menu" id="menuLink" class="menu-link"> <!-- Hamburger icon --> <span>& ...

Take action upon window.open

I have a code snippet here that opens a window. Is it possible to make an ajax call when this window is opened? window.open("http://www.google.com"); For instance, can I trigger the following ajax call once the window is open: var signalz = '1&apos ...

Retrieving every single .json file present in a specific folder

I'm working on developing an Android app that utilizes JSON data. Is there a method to establish a directory structure similar to this: http://......./jsons/*.json Or is there another way to append additional data into a JSON file (such as a.json) a ...

In the realm of React Native, an error arises when attempting to access 'this._nativeModule.isBluetoothEnabled', as the reference to null prevents it from

Recently, I delved into working with react native and attempted to incorporate react-native-bluetooth-classic into my project. The URL for the API overview can be found here. However, I encountered an issue that has me stuck: "TypeError: null is not ...

Store the fetched data as JSON in the local storage

Struggling to find a solution after reading several articles, I am working on fetching a large JSON from an API and I want to cache the response in the localStorage. The goal is for the script to check for an object with the requested ID in the cached JSON ...

Utilizing Java to extract JSON path values and assign them to variables

I'm facing an issue with my code for parsing a JSON string into an object. Previously, I had the following code: public AgentStrategy parseJsonToObject(String jsonString) { Gson gson = new Gson(); AgentStrategy agent = gson.fromJson(jsonString ...

Are there any jQuery Context Menu plugins clever enough to handle window borders seamlessly?

After reviewing UIkit, as well as some other jQuery Context Menu plugins, I have noticed that they all tend to exhibit a similar behavior: The actual menu div renders outside the window, causing valuable content to be hidden from view. Is there a way to ...

Issue with cout in C++ node.js module?

Greetings, I am new to C++ and currently working on tweaking an existing native node module. My goal is to insert cout statements within the module in order to display information that I believe will be beneficial for me. NAN_METHOD(Context2d::SetFillRul ...