Page 2 of 2 FirstFirst 12
Results 21 to 24 of 24
  1. #21
    Stoyicker is offline Member
    Join Date
    Jan 2012
    Posts
    32
    Rep Power
    0

    Default Re: "File" catalog-type. It should be time-persistent, but why it isn't?

    Test ID: t1
    What: Testing table creation.
    How: Run the code once. Then run it another one. If everything has gone right, the second time should report an exception because it can't create an already existing table.
    Code:
    Java Code:
        private static void run() throws Exception {
            Connection conn;
            Statement statement = null;
            Class.forName("org.hsqldb.jdbc.JDBCDriver");
            conn = DriverManager.getConnection("jdbc:hsqldb:file:testdb", "SA", "");
            statement = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                    ResultSet.CONCUR_UPDATABLE);
            ArrayList<String> data = new ArrayList<String>();
            data.add("field1 varchar(255)");
            data.add("field2 varchar(255)");
            data.add("field3 varchar(255)");
            data.add("field4 varchar(255)");
            data.add("field5 varchar(255)");
            String command = "CREATE TABLE Table_Test5 (";
            int counter = 0;
            for (String target : data) {
                command = command.concat(target);
                counter++;
                if (counter < data.size()) {
                    command = command.concat(", ");
                }
            }
            command = command.concat(")");
            System.out.println("Command to run: " + command);
            statement.executeUpdate(command);
        }
    Code in main method:
    Java Code:
            try {
                isolatedRun.run();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
    Results: No exception is reported. This means than data is not stored from one run to another.

    Test ID: t2
    What: Testing table persistance during a run.
    Code: [B]Exactly the same[\B] than for t1.
    Code in main method:
    Java Code:
            try {
                isolatedRun.run();
    			isolatedRun.run();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
    Results: An exception is thrown in the line corresponding to the second isolatedRun.run() call, reporting that the requested table can't be created because it already exists.

    The only possibility I'm able to think of is some kind of HSQL/Java bug...
    Last edited by Stoyicker; 01-25-2012 at 05:34 PM.

  2. #22
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,861
    Rep Power
    19

    Default Re: "File" catalog-type. It should be time-persistent, but why it isn't?

    You're creating a table there.
    OK.
    Since this is a fairly basic (indeed fundamental) part of db work, I think declaring it a bug in HSQL, which I get the impression is used quite a lot in embedded work, is a bit hasty.

    Change your connection string to:
    "jdbc:hsqldb:file:testdb;shutdown=true"

    Also I note you are not closing your connections...closing is very important in this test as it ensures nothing has been left open by accident. Always clean up after yourself.

  3. #23
    Stoyicker is offline Member
    Join Date
    Jan 2012
    Posts
    32
    Rep Power
    0

    Default Re: "File" catalog-type. It should be time-persistent, but why it isn't?

    Yeah, finally, the key was in that shutdown=true add. I read it in the guide, but I didn't think I needed it as I had thought of always manually closing the stuff through SQL.close(). And at the beginning of this problem, when I still was suspecting that something was wrong in that method, I started to not to include it in the tests and, as the results were anyway wrong, I kept non-including it in order to focus on the rest of the code. Definitively, by the combination of recovering the SQL.close() method and adding the shutdown=true property, everything is ok now. I'm attaching the last tests I've performed. They don't use the SQL class, because although I've also performed the equivalent tests to it, I think they don't make much sense as the definitive class is not ready yet.

    standaloneTests.txt

    Thank you very much Tolls, indeed.

  4. #24
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,861
    Rep Power
    19

    Default Re: "File" catalog-type. It should be time-persistent, but why it isn't?

    I was looking at the docs and (though it didn't really explicitly state it) there did seem to be a hint that it did stuff on shutdown.
    The docs could definitely do with making that a bit clearer!

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 6
    Last Post: 02-10-2011, 09:55 AM
  2. Creating a file "type"
    By Hello World in forum New To Java
    Replies: 1
    Last Post: 03-04-2010, 02:57 AM
  3. Replies: 1
    Last Post: 05-20-2009, 08:46 PM
  4. Replies: 0
    Last Post: 11-22-2008, 01:49 AM
  5. Replies: 1
    Last Post: 10-20-2008, 07:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •