Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9193819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:15:22+00:00 2026-06-17T21:15:22+00:00

Currently I made a connection to a database in this way: MyClass.java try {

  • 0

Currently I made a connection to a database in this way:

MyClass.java

try {
    DataSource datasource = JNDILoader.getDataSourceObject(pathToSource);
    Class.forName("net.sourceforge.jtds.jdbc.Driver");
    connection = datasource.getConnection();
    stmt = connection.prepareStatement("{call storageProcedureXXX(?,?)}");
    stmt.setString(1, "X");
    stmt.setString(2, "Y");            
    result = stmt.executeQuery();
}catch (SQLException){
    //TODO
}catch(Exception){
    //TODO
} 

That works for 1 class that makes the requests for the data, but , would be better if I create a singleton class and get the connection from it? (performance?, maintenability?, simplicity?). Which option would be better: Singleton vs StorageProcedures per each request?.

Note: At the end, the application (Restful Web Service) will need to connect to different databases to load data for different specialized classes, even , the classes would need loads data from plain text.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:15:24+00:00Added an answer on June 17, 2026 at 9:15 pm

    First of all you are mixing two different things: singleton and stored procedures. Singleton is design pattern, and stored procedures are procedures executed on database, typically encapsulating some business logic.

    What you wrote is not really preferred way of connecting to database. If you have many request and create one connection for each request son you will have problems with too many connections to database. You should use connection pool. The most famous for Java is DBCP. Another one is c3p0.

    For connection on different databases you should use something like Hibernate.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently i have made a bar chart from a listbox from this example: http://weblogs.thinktecture.com/cnagel/2011/06/wpf-listbox-as-bar-chart.html
There is a Java paradigm for database access implemented in the Java DataSource .
Our application is currently made up of two big entities: C# ASPX files, and
I'm currently working on a semantic web e-learning project. I've made an ontology and
I'm currently learning iPhone applications development, and I made some online tutorials to learn
I have an online text editor, very well made however it does not currently
I am currently trying to debug my Java servlet which is having problems interfacing
I'm currently maintaining a small-medium sized java web application (using only plain JSPs/Servlets) that
I am currently working with Java, MongoDB and several threads. For each threads, I
This is a very broad question, but hopefully I can get useful tips. Currently

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.