Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Fetch all constraints, schema name through java code from oracle database

 
Ankit Kr Sah
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want some samples of code to fetch all constraints schema name right now i can get table names, number of columns in table, their datatype and name of columns through resultsetmetadeta need code some what like this
 
chris webster
Bartender
Posts: 2407
32
Linux Oracle Postgres Database Python Scala
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"I want doesn't get" as my Mum used to say...

Oracle provides a lot of database catalogue views such as ALL_CONSTRAINTS that will give you a vast amount of information about your database objects, provided you have access to them (talk to your DBA).

I suggest you do the following:

  • Figure out what specific information you actually need.
  • Figure out which DB catalogue views you need to look at in order to find this information.
  • Write the SQL to fetch that information from the relevant DB catalogue views.
  • Test your SQL on the database using your SQL interpreter (e.g. SQL*Plus or SQL Developer) with the appropriate user.
  • Then decide how you want to be able to access this data in future, and write a program to run the SQL as necessary.

  • If you try these things out but still have difficulties, come back and ask for help with a specific problem.
     
    Martin Vajsar
    Sheriff
    Pie
    Posts: 3751
    62
    Chrome Netbeans IDE Oracle
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    While it should be possible to get a lot of info using DatabaseMetaData, I'd also opt for the catalogue views in Oracle.

    Just a nitpick:
    chris webster wrote:... provided you have access to them (talk to your DBA).

    I always had the impression that ALL_* views are always available - they describe objects the user has been granted access to. Isn't it the case?
     
    chris webster
    Bartender
    Posts: 2407
    32
    Linux Oracle Postgres Database Python Scala
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Martin Vajsar wrote:Just a nitpick:
    chris webster wrote:... provided you have access to them (talk to your DBA).

    I always had the impression that ALL_* views are always available - they describe objects the user has been granted access to. Isn't it the case?

    Sorry - you're right of course. I was thinking about all the other DBA-views that may not necessarily be visible to the user. I think I've been permanently scarred by my last project working on a site where the DB was so totally locked down that the Oracle developers were lucky if they could query DUAL!
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic