-->
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.  [ 4 posts ] 
Author Message
 Post subject: Check database availability
PostPosted: Mon Jul 09, 2007 4:50 am 
Regular
Regular

Joined: Thu Apr 05, 2007 7:05 am
Posts: 53
Location: Troisdorf, Germany
Hi,

I want to check at the beginning of my program if the database is available. Has somebody an idea how I can check this?

Carina

I"m using:
Hibernate version: 3.2 beta 8
Name and version of the database you are using: Oracle 10g

Full stack trace of any exception that occurs:
Code:
2007-07-09 10:33:30,264 INFO  [org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:41)] Using Hibernate built-in connection pool (not for production use!)
2007-07-09 10:33:30,270 INFO  [org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:42)] Hibernate connection pool size: 20
2007-07-09 10:33:30,270 INFO  [org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:45)] autocommit mode: false
2007-07-09 10:33:30,307 INFO  [org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:80)] using driver: oracle.jdbc.driver.OracleDriver at URL: jdbc:oracle:thin:@bio-ora:1521:chemdb02
2007-07-09 10:33:30,307 INFO  [org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:86)] connection properties: {user=csr, password=****}
2007-07-09 10:33:30,754 WARN  [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:117)] Could not obtain connection metadata
java.sql.SQLException: Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
The Connection descriptor used by the client was:
bio-ora:1521:chemdb02

   at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
   at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:261)
   at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387)
   at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:439)
   at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
   at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
   at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
   at java.sql.DriverManager.getConnection(DriverManager.java:525)
   at java.sql.DriverManager.getConnection(DriverManager.java:140)
   at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
   at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:84)
   at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
   at de.fhg.scai.bio.csr.io.database.communication.HibernateUtil.<clinit>(HibernateUtil.java:16)
   at de.fhg.scai.bio.csr.workflows.Workflow.run(Workflow.java:386)
   at de.fhg.scai.bio.csr.workflows.Workflow.main(Workflow.java:1681)
2007-07-09 10:33:30,831 INFO  [org.hibernate.dialect.Dialect.<init>(Dialect.java:152)] Using dialect: org.hibernate.dialect.Oracle9Dialect
2007-07-09 10:33:30,850 INFO  [org.hibernate.transaction.TransactionFactoryFactory.buildTransactionFactory(TransactionFactoryFactory.java:31)] Using default transaction strategy (direct JDBC transactions)
2007-07-09 10:33:30,853 INFO  [org.hibernate.transaction.TransactionManagerLookupFactory.getTransactionManagerLookup(TransactionManagerLookupFactory.java:33)] No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
2007-07-09 10:33:30,854 INFO  [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:143)] Automatic flush during beforeCompletion(): disabled
2007-07-09 10:33:30,854 INFO  [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:147)] Automatic session close at end of transaction: disabled
2007-07-09 10:33:30,860 INFO  [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:162)] Scrollable result sets: disabled
2007-07-09 10:33:30,861 INFO  [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:170)] JDBC3 getGeneratedKeys(): disabled
2007-07-09 10:33:30,861 INFO  [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:178)] Connection release mode: auto
2007-07-09 10:33:30,874 INFO  [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:196)] Default schema: CSR
2007-07-09 10:33:30,875 INFO  [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:205)] Default batch fetch size: 1
2007-07-09 10:33:30,875 INFO  [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:209)] Generate SQL with comments: disabled
2007-07-09 10:33:30,875 INFO  [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:213)] Order SQL updates by primary key: disabled
2007-07-09 10:33:30,875 INFO  [org.hibernate.cfg.SettingsFactory.createQueryTranslatorFactory(SettingsFactory.java:382)] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
2007-07-09 10:33:30,878 INFO  [org.hibernate.hql.ast.ASTQueryTranslatorFactory.<init>(ASTQueryTranslatorFactory.java:24)] Using ASTQueryTranslatorFactory
2007-07-09 10:33:30,879 INFO  [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:221)] Query language substitutions: {}
2007-07-09 10:33:30,879 INFO  [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:226)] JPA-QL strict compliance: disabled
2007-07-09 10:33:30,879 INFO  [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:231)] Second-level cache: enabled
2007-07-09 10:33:30,880 INFO  [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:235)] Query cache: disabled
2007-07-09 10:33:30,880 INFO  [org.hibernate.cfg.SettingsFactory.createCacheProvider(SettingsFactory.java:369)] Cache provider: org.hibernate.cache.NoCacheProvider
2007-07-09 10:33:30,880 INFO  [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:250)] Optimize cache for minimal puts: disabled
2007-07-09 10:33:30,880 INFO  [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:259)] Structured second-level cache entries: disabled
2007-07-09 10:33:30,904 INFO  [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:286)] Statistics: disabled
2007-07-09 10:33:30,904 INFO  [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:290)] Deleted entity synthetic identifier rollback: disabled
2007-07-09 10:33:30,905 INFO  [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:305)] Default entity-mode: pojo
2007-07-09 10:33:30,905 INFO  [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:309)] Named query checking : enabled
2007-07-09 10:33:30,981 INFO  [org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:161)] building session factory
2007-07-09 10:33:33,077 INFO  [org.hibernate.impl.SessionFactoryObjectFactory.addInstance(SessionFactoryObjectFactory.java:82)] Not binding factory to JNDI, no JNDI name configured
2007-07-09 10:33:33,156 WARN  [org.hibernate.util.JDBCExceptionReporter.logExceptions(JDBCExceptionReporter.java:77)] SQL Error: 0, SQLState: null
2007-07-09 10:33:33,156 ERROR [org.hibernate.util.JDBCExceptionReporter.logExceptions(JDBCExceptionReporter.java:78)] Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
The Connection descriptor used by the client was:
bio-ora:1521:chemdb02


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 09, 2007 9:26 am 
Regular
Regular

Joined: Sat May 20, 2006 3:49 am
Posts: 78
you can test if the jdbc drivers are available with the following statement:

Class.forName("oracle.jdbc.driver.OracleDriver");

you can also test the connection to the database with the java.sql.DriverManager class:

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

// test db connection
log.debug("trying to create db connection ...");
DriverManager.getConnection(url, user, password);
log.info("database connection created successfully");


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 09, 2007 10:00 am 
Regular
Regular

Joined: Thu Apr 05, 2007 7:05 am
Posts: 53
Location: Troisdorf, Germany
Thank you. The Driver Manager gives me feedback about the availability of the database. But one more question: Which type of object is "p"? I'm using HibernateTools and there the properties are read out the config file. Can I get this information somehow?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 09, 2007 11:04 am 
Regular
Regular

Joined: Sat May 20, 2006 3:49 am
Posts: 78
N-te Jr. wrote:
Thank you. The Driver Manager gives me feedback about the availability of the database. But one more question: Which type of object is "p"? I'm using HibernateTools and there the properties are read out the config file. Can I get this information somehow?


p ist simply a java.util.Property object with my hibernate properties. If you use a hibernate.properties file, you could reuse these properties for your db-test.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.