- This topic has 3 replies, 3 voices, and was last updated 17 years, 10 months ago by Brian Fernandes.
-
AuthorPosts
-
shantanu_sMemberI am trying to create a stand-alone db-aware java app using Hibernate to access a Oracle database hosted on my ISP’s server.
<?xml version=’1.0′ encoding=’utf-8′?>
<!DOCTYPE hibernate-configuration PUBLIC
“-//Hibernate/Hibernate Configuration DTD//EN”
“http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd”><hibernate-configuration>
<session-factory>
<property name=”hibernate.connection.driver_class”>oracle.jdbc.driver.OracleDriver</property>
<property name=”hibernate.connection.url”>jdbc:oracle:thin:@10.15.68.23:1521:eprdev</property>
<property name=”hibernate.connection.username”>x</property>
<property name=”hibernate.connection.password”>x</property>
<property name=”hibernate.connection.pool_size”>10</property>
<property name=”show_sql”>true</property>
<property name=”dialect”>org.hibernate.dialect.Oracle9Dialect</property>
<property name=”hibernate.hbm2ddl.auto”>update</property>
<!– Mapping files –>
<mapping resource=”contact.hbm.xml”/>
</session-factory>
</hibernate-configuration><?xml version=”1.0″?>
<!DOCTYPE hibernate-mapping PUBLIC
“-//Hibernate/Hibernate Mapping DTD 3.0//EN”
“org/hibernate/hibernate-mapping-3.0.dtd”>
<hibernate-mapping>
<class name=”test.Contact” table=”CONTACT”>
<id name=”id” type=”long” column=”ID” >
<generator class=”assigned”/>
</id><property name=”firstName”>
<column name=”FIRSTNAME” />
</property>
<property name=”lastName”>
<column name=”LASTNAME”/>
</property>
<property name=”email”>
<column name=”EMAIL”/>
</property>
</class><class name=”test.Book” table=”book”>
<id name=”lngBookId” type=”long” column=”id” >
<generator class=”increment”/>
</id><property name=”strBookName”>
<column name=”bookname” />
</property>
</class><class name=”test.Insurance” table=”insurance”>
<id name=”lngInsuranceId” type=”long” column=”ID” >
<generator class=”increment”/>
</id><property name=”insuranceName”>
<column name=”insurance_name” />
</property>
<property name=”investementAmount”>
<column name=”invested_amount” />
</property>
<property name=”investementDate”>
<column name=”investement_date” />
</property>
</class>
</hibernate-mapping>/
package test;import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;public class Booktest {
public static void main(String[] args) {
Session session = null;try{
// This step will read hibernate.cfg.xml and prepare hibernate for use
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();org.hibernate.Transaction tx = session.beginTransaction();
//Create new instance of Contact and set values in it by reading them from form object
System.out.println(“Inserting Book object into database..”);
Book book = new Book();
book.setStrBookName(“Hibernate Tutorial 2”);
session.save(book);
System.out.println(“Book object persisted to the database.”);
tx.commit();
session.flush();
session.close();
}catch(Exception e){
System.out.println(e.getMessage());
}finally{
}
}
}org.hibernate.exception.GenericJDBCException: Cannot open connection
at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
at org.hibernate.jdbc.AbstractBatcher.openConnection(AbstractBatcher.java:384)
at org.hibernate.jdbc.JDBCContext.connect(JDBCContext.java:141)
at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:88)
at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:49)
at org.hibernate.transaction.JDBCTransactionFactory.beginTransaction(JDBCTransactionFactory.java:19)
at org.hibernate.jdbc.JDBCContext.beginTransaction(JDBCContext.java:204)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1007)
at testHibernate.main(testHibernate.java:34)
Caused by: java.sql.SQLException: Io exception: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=153092352)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4))))
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:333)
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:404)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:468)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:314)
at java.sql.DriverManager.getConnection(DriverManager.java:543)
at java.sql.DriverManager.getConnection(DriverManager.java:163)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
at org.hibernate.jdbc.AbstractBatcher.openConnection(AbstractBatcher.java:381)
… 7 moreI am working with:
WebSphere 5.1.2(have included the hibernate and oracle jar’s and various others)
Any advice you can offer would be greatly appreciated…Thanks
Haris PecoMemberIt looks like your IP address (10.15.68.23) or port (1521) is not correct. The Oracle listener has not started at this address/port.
Please check if you made a typing error or your provider has sent you incorrect information.You can try to access this database from the DB Explorer as well.
Regards,
shantanu_sMemberThanks Snpe for the quick assistance but the IP and port are absolutely correct .. As i have also connected to the same db using my sql prompt. Have checked the IP and port but they are correct.
I think the problem might be due to jar’s i have included i am attaching the .classpath file. If it helps 😀
<?xml version=”1.0″ encoding=”UTF-8″?>
<classpath>
<classpathentry kind=”src” path=””/>
<classpathentry kind=”con” path=”org.eclipse.jdt.launching.JRE_CONTAINER”/>
<classpathentry kind=”lib” path=”F:/e-books/hibernate/lib/ant-1.6.2.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/hibernate/lib/ant-antlr-1.6.2.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/hibernate/lib/ant-junit-1.6.2.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/hibernate/lib/ant-launcher-1.6.2.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/hibernate/lib/antlr-2.7.4.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/hibernate/lib/ant-swing-1.6.2.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/hibernate/lib/c3p0-0.8.5.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/hibernate/lib/cglib-full-2.0.2.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/hibernate/lib/cleanimports.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/hibernate/lib/commons-collections-2.1.1.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/hibernate/lib/commons-logging-1.0.4.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/hibernate/lib/concurrent-1.3.2.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/hibernate/lib/connector.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/hibernate/lib/dom4j-1.5.2.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/hibernate/lib/ehcache-1.1.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/hibernate/lib/hibernate3.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/hibernate/lib/jaas.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/hibernate/lib/jacc-1_0-fr.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/hibernate/lib/jaxen-1.1-beta-4.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/hibernate/lib/jboss-cache.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/hibernate/lib/jboss-common.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/hibernate/lib/jboss-jmx.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/hibernate/lib/jboss-remoting.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/hibernate/lib/jboss-system.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/hibernate/lib/jdbc2_0-stdext.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/hibernate/lib/jgroups-2.2.7.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/hibernate/lib/jta.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/hibernate/lib/junit-3.8.1.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/hibernate/lib/log4j-1.2.9.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/hibernate/lib/mysql-connector-java-3.0.16-ga-bin.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/hibernate/lib/mysql-connector-java-3.1.6-bin.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/hibernate/lib/oscache-2.1.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/hibernate/lib/proxool-0.8.3.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/hibernate/lib/swarmcache-1.0rc2.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/hibernate/lib/versioncheck.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/hibernate/lib/xerces-2.6.2.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/hibernate/lib/xml-apis.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/lib/classes12.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/lib/commons-beanutils.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/lib/commons-collections.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/lib/commons-dbcp.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/lib/commons-digester.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/lib/commons-fileupload.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/lib/commons-lang.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/lib/commons-logging.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/lib/commons-pool.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/lib/commons-validator.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/lib/log4j-1.2.4.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/lib/struts.jar”/>
<classpathentry kind=”lib” path=”F:/e-books/lib/struts-legacy.jar”/>
<classpathentry kind=”output” path=””/>
</classpath>
Brian FernandesModeratorShantanu,
I noticed you’re using classes12.jar as your Oracle driver. This JAR is the root of the problem most of the time, it is ideally meant for use with Java 1.3.
Replace that with the more recent ojdbc14.jar and see if that helps.More info here: http://www.myeclipseide.com/PNphpBB2+file-viewtopic-t-14580.html
-
AuthorPosts