Ah ha!! And of course, when I tested it from SQuirrelSQl, I dutifully
removed the .h2.db without even thinking about it.

Made a quick change:

      String dbfile = file.getAbsolutePath().replaceAll(".h2.db", "");
      System.out.println(dbfile);
      ds.setUrl("jdbc:h2:file:" + dbfile);

which works for now. Thanks very much!

Your point about the URL probably being wrong when the tables are
missing occurred to me too, but I kept missing the extension. :)

Cheers,

Sean

On Jun 16, 1:23 pm, Thomas Mueller <[email protected]>
wrote:
> Hi,
>
> The problem is most likely the ".h2.db":
>
> >      File file = File.createTempFile(dbname, ".h2.db");
> >      ds.setUrl("jdbc:h2:file:" + file.getAbsolutePath());
>
> With dbname = "/data/test", the URL would become:
> jdbc:h2:file:/data/test.h2.db
> which would try to open the file:
> /data/test.h2.db.h2.db (twice the ".h2.db" suffix).
> This file doesn't exist, so it's created (creating a new database).
>
> Instead, I suggest to use:
>
> File file = File.createTempFile(dbname, ".h2.db");
> ds.setUrl("jdbc:h2:file:" + System.getProperty("java.io.tmpdir") + "/"
> + dbname);
>
> Or something similar.
>
> Note to self: If the exception is "Table ... not found", then in many
> cases the database URL is wrong. Maybe it makes sense to add "(this
> database is empty)" to the error message if the database is empty, so
> that people understand what could be the problem. Or even: "(this
> database is empty - did you open the right database?)".
>
> Regards,
> Thomas

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/h2-database?hl=en.

Reply via email to