问题
I created a schema and few tables manually using the Eclipse database development perspective. But whenever I try to access the table from code, I get "Schema does not exist" error. However, if I create the tables within my program just before using them, all go well. Do I have to create the tables each time I connect to database? Since, I am testing my code, I have to restart the project multiple times.
回答1:
Three common reasons for "table does not exist" when you think you've already created the tables:
- You are connecting to a different database than you think you were connecting to, and since you specified "create=true" on the Connection URL, Derby quietly created a new empty database for you.
- You are using the "in-memory" configuration of Derby, which means that when the database is closed (or your application exits), all the contents of the database disappear.
- You are connecting to the database as a different user, and you aren't issuing the SET SCHEMA statement, so you are using the default schema name, which is based on your user name, and so the two schemas are different and have completely different tables, so the table you created doesn't seem to exist when you use the other schema.
来源:https://stackoverflow.com/questions/22996818/is-it-necessary-to-create-tables-each-time-you-connect-the-derby-database