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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:05:46+00:00 2026-05-14T03:05:46+00:00

I am connecting a MYSQL database through hibernate and i seem to have processes

  • 0

I am connecting a MYSQL database through hibernate and i seem to have processes that are not being killed after they are finished in the session. I have called flush and close on each session but when i check the server the last processes are still there with a sleep command. This is a new problem which i am having and was not the case yesterday. Is there any way i can ensure the killng of theses processes when i am done with a session.
Below is an example of one of my classes.

    public JSONObject check()
{
    //creates a new session needed to add elements to a database
    Session session = null;

    //holds the result of the check in the database
    JSONObject check = new JSONObject();
    try{
        //creates a new session needed to add elements to a database
        SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); 
        session = sessionFactory.openSession();


        if (justusername){

            //query created to select a username from user table
            String hquery = "Select username from User user Where username = ? ";

            //query created
            Query query = session.createQuery(hquery);

            //sets the username of the query the values JSONObject contents
            query.setString(0, username);

            // executes query and adds username string variable 
            String user = (String) query.uniqueResult();

            //checks to see if result is found (null if not found)
            if (user == null)
            {
                //adds false to Jobject if not found
                check.put("indatabase", "false");
            }
            else
            {
                check.put("indatabase", "true");
            }

            //adds check to Jobject to say just to check username
            check.put("justusername", true);

        }
        else
        {
            //query created to select a username and password from user table
            String hquery = "Select username from User user Where username = :user and password = :pass ";
            Query query = session.createQuery(hquery);

            query.setString("user", username);
            query.setString("pass", password);

            String user = (String) query.uniqueResult();

            if(user ==null)
            {
                check.put("indatabase", false);
            }
            else
            {
                check.put("indatabase", true);
            }

            check.put("justusername", false);

        }


        }catch(Exception e){

        System.out.println(e.getMessage());
            //logg.log(Level.WARNING, " Exception", e.getMessage());

    }finally{
    // Actual contact insertion will happen at this step

        session.flush();
        session.close();

    }
    //returns Jobject
    return check;
}
  • 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-05-14T03:05:46+00:00Added an answer on May 14, 2026 at 3:05 am

    You should call sessionFactory.close() at the end, that will release all connections in the connection pool.

    Note that normally you should have a single session factory for your whole app, which can then create as many sessions as you need. Creating the session factory is very costly.

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

Sidebar

Related Questions

I have followed his popular tutorial to connect Android to MySQL: http://www.helloandroid.com/tutorials/connecting-mysql-database It is
I have an ASP.NET MVC2 site connecting to a MySQL database via DbLinq. There
I am writing a game server that requires connecting to a MySQL database server
i am connecting to a mysql database through excel using odbc what does this
I have a java code and I am connecting to the mysql database with
I have a mySQL database that tracks our projects and drives our website's display
I'm using Visual Studio 2010 and connecting to MySQL database through MySqlODBC 5.1 driver.
I want to display data in my own format from Mysql database connecting through
I have pages that have content dynamically added through mySQL queries. Most of these
I'm using a MySQL database and accessing it through Java. PreparedStatement prep1 = this.connection.prepareStatement(

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.