my dog learned polymorphism*
The moose likes JDBC and the fly likes  java.sql.SQLException: Io exception: The Network Adapter could not establish the connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark " java.sql.SQLException: Io exception: The Network Adapter could not establish the connection" Watch " java.sql.SQLException: Io exception: The Network Adapter could not establish the connection" New topic
Author

java.sql.SQLException: Io exception: The Network Adapter could not establish the connection

Viji Jan
Greenhorn

Joined: Aug 26, 2011
Posts: 1
I am writing code to connect Java to Oracle 10g datbase using hibernate.
Iam using Oracle 10g express edition.

<hibernate-configuration>

<session-factory>

<!-- Database connection settings -->
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.url">jdbcracle:thin:@localhost:1525:xe</property>
<property name="connection.username">user</property>
<property name="connection.password">password</property>

<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>

<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.OracleDialect</property>

<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>

<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>

<mapping class="org.hibernate.example.dto.EmployeeDetails"/>

</session-factory>

</hibernate-configuration>


I can able to connect to database separately.while connecting using hiberate,iam getting " java.sql.SQLException: Io exception: The Network Adapter could not establish the connection" error.Please help.
Shinil Mohan
Ranch Hand

Joined: Aug 24, 2011
Posts: 37

Can you check you are using the correct version of jar files / JDK, also may be you can try connect to the DB using any other tool to make sure the DB is up and running fine. If you use Eclipse then you can use Data Source Explorer to test this.

Few notes available in oracle site about the dependency of the jar/java etc.. "•Oracle Database XE does not support JDK 1.2 and JDK 1.3, including all classes12*.* files. You need to use the ojdbc14.jar file with JDK 1.4.x instead."

Refer to the URL http://download.oracle.com/docs/cd/B25329_01/doc/appdev.102/b25320/getstart.htm
Shinil Mohan
Ranch Hand

Joined: Aug 24, 2011
Posts: 37

Also if you find all the configuration seems to be correct, may be you can create a standalone java program to test the connectivity to the DB and make sure you have all the Java/Jar versions correct and the DB is up and running correctly. May be some thing like this http://www.javadb.com/connect-to-a-database-and-read-from-table
Shinil Mohan
Ranch Hand

Joined: Aug 24, 2011
Posts: 37

A sample hibernate cnfg file i used in my application to connect to mysql, which is working fine... May be you can refer to this too..

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/dbhibernate</property>
<property name="hibernate.connection.username">root</property>
<property name="connection.password">****</property>
<property name="connection.pool_size">1</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="show_sql">true</property>
<mapping class="com.keane.tjxCollaboration.Entity.Employee" />
<mapping class="com.keane.tjxCollaboration.Entity.Department" />
</session-factory>
</hibernate-configuration>
 
Consider Paul's rocket mass heater.
 
subject: java.sql.SQLException: Io exception: The Network Adapter could not establish the connection