Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Database and Hibernate connection problem

  1. #1
    Junior Member
    Join Date
    Aug 2014
    Posts
    10
    My Mood
    Confused
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Database and Hibernate connection problem

    Hi,

    I'm using Netbeans 7.4 - GUI is hand-coded, JavaDB using Embedded Connection. The project I'm working on is an SE desktop distributable application but it is NOT a CRUD.

    I'm having problems using Hibernate to create POJOs of the data in the database. I have researched but I can't find the relevant info to use Hibernate in this scenario. Could someone point me in the direction for the solution to this please.


  2. #2

    Default Re: Database and Hibernate connection problem

    The problem was that just typical Hibernate session did not throw any exception while using it without database connected. But this piece of code does throw an exception when database not connected (so it can be used as a test):

    Properties p = hibernateConnection.getCfg().getProperties();

    String url = p.getProperty("hibernate.connection.url");
    String user = p.getProperty("hibernate.connection.username");
    String password = p.getProperty("hibernate.connection.password");

    DriverManager.getConnection(url, user, password).close();
    So, simple try-catch can be used. If an exception is caught, connection is dead.

    I used this for regular checking of database connection. On application deploy, a TimerTask is scheduled to run every minute. When it catches an exception, it sets a static variable dbAvailable to false (otherwise to true). This variable is being checked on every HTTP client request and if it's true, error 503 is sent back in response.

Similar Threads

  1. Problem with CRUD connection to database, help? :S
    By Issuee in forum What's Wrong With My Code?
    Replies: 0
    Last Post: April 7th, 2014, 10:56 AM
  2. problem in Derby embedded database connection
    By brother in forum JDBC & Databases
    Replies: 6
    Last Post: December 24th, 2012, 02:17 PM
  3. Replies: 1
    Last Post: December 21st, 2012, 10:35 AM
  4. [SOLVED] database connection problem adding,deleting,updating,selecting :(
    By jabaman in forum What's Wrong With My Code?
    Replies: 13
    Last Post: December 6th, 2012, 01:05 PM
  5. MS Access database connection problem
    By faysal40 in forum JDBC & Databases
    Replies: 1
    Last Post: August 29th, 2011, 01:22 AM

Tags for this Thread