derby create table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • oll3i
    Contributor
    • Mar 2007
    • 679

    derby create table

    my function connects to the database but the tables are not created?
    i get Syntax error: Encountered "<EOF>" at line 1, column 187.


    part of my function that is supposed to create the tables
    Code:
     try
                 {
                	 int count=statement.executeUpdate("CREATE TABLE contacts("+
            		   "CONTACT_ID INTEGER NOT NULL PRIMARY KEY, "+
            		   "FIRSTNAME VARCHAR(25) not null, "+
            		   "LASTNAME VARCHAR(25) not null, "+
            		   "EMAIL VARCHAR(60) not null, "+
            		   "CONSTRAINT UNIQUE_EMAIL UNIQUE(EMAIL)");
               
                	 System.out.println("Table contacts created="+count);
               
               
               
                	 count=statement.executeUpdate("create table BOOKS("+
            		"BOOK_ID INTEGER NOT NULL PRIMARY KEY, "+
            		 "AUTHOR VARCHAR(100) not null, "+
            		"TITLE VARCHAR(100) not null, "+
            		"ISBN VARCHAR(10) not null, "+
            		 "ISSUE_YEAR SMALLINT not null, "+
            		 "CONSTRAINT UNIQUE_ISBN UNIQUE(ISBN)");
                	 
                	 System.out.println("Table books created="+count);
                 }
                 catch (SQLException ex)
                 {
                  System.out.println(ex.getMessage());
                 }
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Cute, which one of the two statements failed?

    kind regards,

    Jos

    Comment

    • oll3i
      Contributor
      • Mar 2007
      • 679

      #3
      the first one
      when i try to return rows from the table it says that the table does not exist
      connection to the database doesn't throw any errors (had classNotFoundEx ception before)

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by oll3i
        the first one
        when i try to return rows from the table it says that the table does not exist
        connection to the database doesn't throw any errors (had classNotFoundEx ception before)
        Well, the SQL parser complained about a syntax error near column 187; all you
        have to do is count and spot the error (it's a missing right parenthesis). You could
        have known that if you had read the error message.

        kind regards,

        Jos

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          Are you sure that

          1.) The connection code is successful(i.e make sure there are no empty catch blocks on the connection code).
          2.) You are proving the correct table name(s) when doing the select?

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by JosAH
            Well, the SQL parser complained about a syntax error near column 187; all you
            have to do is count and spot the error (it's a missing right parenthesis). You could
            have known that if you had read the error message.

            kind regards,

            Jos
            Duh, I seem to have missed that first post.

            Comment

            • JosAH
              Recognized Expert MVP
              • Mar 2007
              • 11453

              #7
              Originally posted by r035198x
              Duh, I seem to have missed that first post.
              It ain't over yet because now that second SQL statement is going to act up;
              let's see if the OP can spot the error ;-)

              kind regards,

              Jos

              Comment

              • oll3i
                Contributor
                • Mar 2007
                • 679

                #8
                i dont see the error maybe you will spot it i stare at it and see nothing

                Code:
                 int count=statement.executeUpdate(
                            	   "CREATE TABLE CONTACTS ( " 
                        		   + "CONTACT_ID INT NOT NULL GENERATED ALWAYS AS IDENTITY CONSTRAINT CONTACT_PK PRIMARY KEY (START WITH 1, INCREMENT BY 1), "
                        		   + "FIRSTNAME  VARCHAR(25) NOT NULL, " 
                        		   + "LASTNAME  VARCHAR(25) NOT NULL, " 
                        		   + "EMAIL VARCHAR(60) NOT NULL, " 
                        		   + "CONSTRAINT UNIQUE_EMAIL UNIQUE(EMAIL))");
                i get Syntax error: Encountered "(" at line 1, column 112.|#
                thank You thank You thank You :)

                Comment

                • r035198x
                  MVP
                  • Sep 2006
                  • 13225

                  #9
                  Put that sql in a string variable and System.out.prin tln the sql before executing it to see what's passed to the database.

                  Comment

                  Working...