Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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: 6920
  • 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.
 
I will suppress my every urge. But not this shameless plug:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic