File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes relationship/constraints info Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "relationship/constraints info" Watch "relationship/constraints info" New topic
Author

relationship/constraints info

ZhiningZhang
Greenhorn

Joined: Jun 13, 2001
Posts: 18
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
jlrober
Greenhorn

Joined: Jun 25, 2001
Posts: 10
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

Joined: Jun 13, 2001
Posts: 18
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

Joined: Jun 25, 2001
Posts: 10
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

Joined: Jun 13, 2001
Posts: 18
yes, it works!
Thanks, jlrober!!!
-Zhining Zhang
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
"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.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: relationship/constraints info