Link to home
Start Free TrialLog in
Avatar of thomasbau65
thomasbau65

asked on

JPA read mssql table constraints

Hi
I have a MSSQL-DB which I connect with JPA (EclipseLink)
I 'd like to write data to one table which has (when using "MS SQL Server Manager Express" found in the folder Constraints/SomeID) constrains.
Is ist possible to read, using JPA, the values or the SQL-statement stored in the file "SomeID"?
Is there a way to retrieve information from the client side regarding table constraints?
Thanks for helping out
th*
ASKER CERTIFIED SOLUTION
Avatar of Lowfatspread
Lowfatspread
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of thomasbau65
thomasbau65

ASKER

Hi
your statement did not work for me, but gave me the hint to where I had to look for a solution
(table_name dose not exist in  "information_schema.check_constraints" ) on my mssql-server

here my solution:

 
public void getConstrains() throws SQLException
    {
        Statement st0 = conn.createStatement();
        ResultSet res0 = st0.executeQuery("SELECT CONSTRAINT_NAME "
                    + "FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS "
                    + "WHERE TABLE_NAME = '"+tName+"'");
        while(res0.next()){
            String cName = (String)res0.getObject(1);
            
            Statement st1 = conn.createStatement();
            ResultSet res1 = st1.executeQuery("SELECT CHECK_CLAUSE, CONSTRAINT_SCHEMA "
                    + "FROM INFORMATION_SCHEMA.CHECK_CONSTRAINTS "
                    + "WHERE CONSTRAINT_NAME='"+cName+"'");
            while(res1.next())
            {
                
                String const = res1.getString(1)
		String schema= res1.getString(2);
            }
        }
    }

Open in new window

The statement is not correct:
table_name
dose not exist in
information_schema.check_constraints