-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Verbindungstest
PostPosted: Thu Mar 25, 2010 2:32 am 
Newbie

Joined: Tue Mar 23, 2010 2:41 am
Posts: 2
Hallo Zusammen,

ich habe ein Problem. Wenn die eingestellte Datenbank nicht vorhanden ist, läuft er immer in eine Nullreference-Exception.
Um das zu vermeiden, würde ich gerne, beim Start meines Programms, testen ob die Verbindung zur Datenbank möglich ist, um entsprechend zu reagieren.

Habt ihr da eine Idee wie man das realisieren könnte.

Danke und Gruß
Leines


Top
 Profile  
 
 Post subject: Re: Verbindungstest
PostPosted: Thu Mar 25, 2010 3:30 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Ueber die sessionfactory von Hiberante kannst Du folgendermassen die Verbindung manuell testen:

Code:
try {
    java.sql.Connection conn =
   ((org.hibernate.impl.SessionFactoryImpl) sessionfactory).getConnectionProvider().getConnection();
    conn.close();  // Verbindung geglueckt,  Verbindung wieder zumachen
}
catch Exception (x) {
    sys.err ("Verbindung zur Datenbank konnte nicht hergestellt werden: " + x.toString());
}


Top
 Profile  
 
 Post subject: Re: Verbindungstest
PostPosted: Thu Mar 25, 2010 4:46 am 
Newbie

Joined: Tue Mar 23, 2010 2:41 am
Posts: 2
Super, danke.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.