• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to access schema for db2 through java code

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Is there any way to access schema from java code .
Actually i am trying to make connection to db2 .
I want any generalized way.

Thanks
Shrikant
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you explain more what you mean by "access schema?" Do you want to find the schema name? Do you want to access the data in a particular schema?

Regards,
Les
 
shri Sonparote
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I have created all my databse inABC schema.

I made connection to db2 databse using code .


but when try to execute any query using statement .It is refering to table or procs that are in my default schema.
To solve this problem I have to prepend ABC. when I am executing any table or procs from my code.
Other wise using statement object i have to execute command
set current schema =ABC.
But this both the two approch are not useful for me .

I want any approch such that it will refer to ABC schema.


waiting for reply
Shrikant
 
Les Hayden
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have not tried to use that feature of JDBC, but here is my opinion:

In DB2 schema is also your ID in the database. I would doubt that DB2 will let you sign on and then change the schema. Changing the schema before signing on, would serve no purpose.

I typically use the schema.objectname form of referencing database objects in DB2. So if I were doing a select from table XYZ in your example I would use the following SQL:

SELECT col1, col2
FROM ABC.XYZ;

You can also execute a command in DB2 to access another schema from your schema without using the schema prefix, but if there are objects with the same name in your schema, you will have to use the prefix to resolve the ambiguity.

The other alternative would be to login directly to the ABC schema. However, if that is a production schema, many companies restrict access to the schema.

Hope this helps,
Les
 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, DB2 does allow you to change the default. Indeed, our application does it automatically upon every connection. Just issue:



as a statement to the DB as you would any SQL statement.
 
reply
    Bookmark Topic Watch Topic
  • New Topic