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
posted
0
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
posted
0
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
posted
0
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
posted
0
yes, it works! Thanks, jlrober!!! -Zhining Zhang
Frank Carver
Sheriff
Joined: Jan 07, 1999
Posts: 6913
posted
0
"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.