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 7888731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:54:31+00:00 2026-06-03T05:54:31+00:00

I am developing a dashboard application where i need to poll the database continuously

  • 0

I am developing a dashboard application where i need to poll the database continuously (every 30s) for checking whether the database is up and running. In order to find out if the database is working, i am making a simple query to retrieve just 1 row from a table.

Everything works fine, but the problem is the servlet takes an unusually long time to establish a connection to the database and retrieve a row. It takes almost 15 seconds for this process. I copied the same code into a java file to find out whether it still takes that much time. But, as i suspected, it took just 1 or 2 seconds for the java program to run. It seems there is something wrong with the way i am approaching this whole thing.

I wrote the database connectivity code in doGet() function since i need to poll the database repeatedly. Is this the mistake i am committing? Should i write database connectivity code in init() and just write the query in doGet() function?

Any help will be appreciated. Thanks

Here is a part of code that might help you understand my problem:

 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//Send Request to DB CAT
LinkedHashMap<String,String> hm=new LinkedHashMap<String,String>();
   try
   {
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    //CONNECT TO DB
    String serverName = "*****.1dc.com"; // * is just to hide the real database name
    int port = 1535;
    String user = "mbank";
    String password = "****";
    String SID = "mbkwqa";
    String URL = "jdbc:oracle:thin:@" + serverName + ":" + port + ":" + SID;
    Connection conndb = DriverManager.getConnection(URL, user, password);
    String SQL = "select CITY from ADDRESS where rownum<=1";
    Statement stat = conndb.createStatement();
    ResultSet rs = stat.executeQuery(SQL);
    while (rs.next()) 
    {
        System.out.println(rs.getString(1));
    }
    stat.close();
    conndb.close(); 
    hm.put("Server1","OK");
    }
      catch(Exception e)
    {
        hm.put("Server1","Failed");         
    }   
  • 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-03T05:54:33+00:00Added an answer on June 3, 2026 at 5:54 am

    you are connecting to database from doGet function and this is very bad practice. What would happen if you have 100, 1000, 10000 requests to your servlet?

    You need to review your design.

    Please create Connection pool to your Oracle data Source, put it in Servlet ApplicationContext, Create Dao Classes and call your Dao Classes from doGet Servlet.

    I believe these tutorials will help:

    http://balusc.blogspot.com/2008/07/dao-tutorial-data-layer.html

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

Sidebar

Related Questions

I am developing a Dashboard for a web application , dashboard shows various Chart
Developing a C# .NET 2.0 WinForm Application. Need the application to close and restart
Developing an MVC application, i now need to have test other browser versions. Installed
We are developing a dashboard application with a lot of charts, using Highcharts Javascript
I'm developing a dashboard report in SSRS 2008R2, and I need to refresh it
Developing a .NET WinForms application: how can I check if the window is in
Developing a heavily XML-based Java-application, I recently encountered an interesting problem on Ubuntu Linux.
Developing a project of mine I realize I have a need for some level
I am developing a web application for a comapny. This application provides the users
Developing for iPhone, I have a collection of points that I need to make

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.