Incorrect syntax near ' sys.objects '
<p>I am getting an Error Message saying </p>

<blockquote>
  <p>com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near 'sys'.</p>
</blockquote>

<p>And this often means that the SQL-query I've typed is wrong or I am missing a syntax. And I am very certain that this SQL-query I am using is right:</p>

<pre><code>  public static Vector&lt;Vector&lt;String&gt;&gt; getKeys() throws SQLException {
    Vector&lt;Vector&lt;String&gt;&gt; vs = new Vector&lt;Vector&lt;String&gt;&gt;();
    Connection con = Dal2.getConnection();
    Statement stm = con.createStatement();
    ResultSet rSet;
    String sqlString = "SELECT OBJECT_NAME(OBJECT_ID) AS NameofConstraint,"
            +"SCHEMA_NAME(schema_id) AS SchemaName,"
            + "OBJECT_NAME(parent_object_id) AS TableName,"
            +"type_desc AS ConstraintType"
            +"FROM sys.objects"
            +"WHERE type_desc IN ('FOREIGN_KEY_CONSTRAINT','PRIMARY_KEY_CONSTRAINT')";

    try{
        rSet = stm.executeQuery(sqlString);
        while(rSet.next()){
            Vector&lt;String&gt; v = new Vector&lt;String&gt;();
            for(int i=1; i &lt;= v.size(); i++){
                System.out.println(rSet.getString(i) + "\n");
         //                 v.add(rSet.getString(i));
            }
            }
        }
        catch(Exception e){
            e.printStackTrace();
        }
    return vs;
</code></pre>

<p>As you can see I want to print out the SQL result-set on the Java console when I am using the method. But I keep getting syntax error. I've tried the SQL-query in SQL Server and it works fine:</p>

<pre><code>SELECT  OBJECT_NAME(OBJECT_ID) AS NameofConstraint,
        SCHEMA_NAME(schema_id) AS SchemaName, 
        OBJECT_NAME(parent_object_id) AS TableName,
        type_desc AS ConstraintType
FROM sys.objects 
WHERE type_desc IN ('FOREIGN_KEY_CONSTRAINT','PRIMARY_KEY_CONSTRAINT')
</code></pre>