• 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

relationship/constraints info

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, All,
How can I get the infomation of relationship/constraints in DB from jdbc? How to add new relationship to DB using jdbc?
Thanks! -Zhining Zhang
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
which database product are you using?
In Oracle 8 you can query certain Oracle tables to find the information
Example:
use the query
"SELECT constraint_name, contraint_type, deferrable, validated
FROM dba_constraints
WHERE owner = "Scott"
AND table_name = 'Employees'"
the owner statement in the where clause is optional(only needed if the table exists twice in the same database!). You also have to have permissions to these table to access the data.
Jamie

 
ZhiningZhang
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks, jlrober!
I am using SQL Server now, but wish my code would work for ORACLE too ( if possible ). So I do not want to use DB's system objects, and want to use jdbc's features.
I am wondering if DatabaseMetaData has this info. How to use it to get constraint's info?
-Zhining Zhang
 
jlrober
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You probably have already looked into the following DatabaseMetaData methods, but in case you overlooked them:
getExportedKeys(String catalog, String schema, String table)
getImportedKeys(String catalog, String schema, String table)
getPrimaryKeys(String catalog, String schema, String table)
The above are only for primary key/foreign key constraints. I haven't come accross a solution for non-key constraints.
jamie
 
ZhiningZhang
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes, it works!
Thanks, jlrober!!!
-Zhining Zhang
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"ZhiningZhang", "jlrober",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in with a new name which meets the requirements.
Thanks.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic