Discussion:
Connection to DB2 Express with Hibernate
(too old to reply)
k***@zworg.com
2009-04-30 07:45:44 UTC
Permalink
Hi I'm working on a new project based on Spring, Hibernate, Struts, Maven connecting to a DB2Express instance on my machine.

Unfortunately I can't connect to the DB2 Express instance running on my localmachine (this is just for development and testing).

My spring-hibernate-conf file looks like this
{code}


-
-
-
-
- !-- com.ibm.db2.jdbc.app.DB2Driver
com.ibm.db2.jcc.DB2Driver

-
jdbc:db2://localhost:50000/soctar

-
db2admin

-
********


-
-
-
hibernate-config-soctardb.hbm.xml


-
-
org.hibernate.dialect.DB2Dialect
false


-




{code}

The error I'm getting is:

{code}java.lang.ClassNotFoundException: com.ibm.db2.jdbc.app.DB2Driver{code}

I guess I haven't put the right jdbc driver on the classpath. The one I added to the classpath is "db2java.jar" It's not added in the Maven repository, but as separate jar to the project.

When I connect to mysql (I have made the same database in Mysql) I can connect to it without any problems and it's returning the correct results.

If someone could tell what driver I exactly need and how to configure my hibernate conf I would be most happy :)
Thx in advance
k***@zworg.com
2009-04-30 11:49:49 UTC
Permalink
Ok, I got some progress. I seems I did not add the correct jar to the classpath. I put db2jcc.jar on it as well and that gives me now an other error:

{code}
com.ibm.db2.jcc.a.nn: DB SQL Error: SQLCODE=-204, SQLSTATE=42704, SQLERRMC=SOCTAR.CITIZENREJECTIONS, DRIVER=3.52.95
{code}

Searching for these SQL Errors seem to refer to a database schema I have not set....

The search continuous...
Jan M. Nelken
2009-04-30 13:32:46 UTC
Permalink
Post by k***@zworg.com
{code}
com.ibm.db2.jcc.a.nn: DB SQL Error: SQLCODE=-204, SQLSTATE=42704, SQLERRMC=SOCTAR.CITIZENREJECTIONS, DRIVER=3.52.95
{code}
Searching for these SQL Errors seem to refer to a database schema I have not set....
-204 SQLCODE means object not found.

Object name in question is:

SOCTAR.CITIZENREJECTIONS

Schema name (as seen by DB2) is SOCTAR
Object name (Tablename perhaps) is CITIZENREJECTIONS

In your code you may have used UNQUALIFIED TABLE NAME - in this case
CITIZENREJECTIONS - which was prepended by DB2 with derived SCHEMA NAME - in
this case derived from authorization id perhaps?

Is SOCTAR an authorization id you use to connect to DB2?


Jan Nelken
p***@solnetsolutions.co.nz
2009-05-26 03:22:16 UTC
Permalink
Hi DInobe,

IIRC, DB2 will set the current schema to be that for the user who you logging in with. The option we used with Hibernate was to add the parameter currentSchema to the data source that hibernate was configured to use. Alternatively I think there is a way in the hibernate mapping to specify the default schema.

jdbc:db2://localhost:50000/nie:currentSchema=nhi


regards,
Paul Morris

Loading...