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.
Asked
Active
Viewed 3,039 times
2
-
If you have a database, and create tables in that database, they will not be deleted unless the table is dropped. Do you by any chance know the tables might be being dropped somewhere? – Drew Apr 10 '14 at 19:09
-
@Drew How could they be? I mean I can see the Schema and Tables I created manually in the DB Perspective. But from code, a simple select statement gives the Schema Does not exist error. – Anas Apr 10 '14 at 19:14
-
Good question! And gotcha. Can you validate whether the tables were actually created through whatever interface Apache provides to check out the db? – Drew Apr 10 '14 at 19:20
-
Yes! I have selected all the tables from SYS.SYSTABLES and it does not show the ones created by me. But why? How can I sync it so that whenever I manually create a table it also shows up in code? – Anas Apr 10 '14 at 19:39
-
Hmmm...mind sharing the code you used to create the tables? – Drew Apr 10 '14 at 19:52
-
Well, I rephrase: I have created tables from the SQL Editor provided by Eclipse. I used simple queries to create table. I executed that script which created the tables. I have not created any table through code yet and I don't want to. – Anas Apr 10 '14 at 19:56
1 Answers
5
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.

Bryan Pendleton
- 16,128
- 3
- 32
- 56
-
Can you give exaplnation about section 3? What is the SET SCHEMA statement I should use? – CrazySynthax Nov 21 '17 at 21:56
-
1@CrazySynthax I know it is way too far back. But still this answer just saved me a lot of time an effort. So what is the SET SCHEMA? It's a call on your connection object like this `connection.setSchema("SCHEMA_NAME")`. – user1561358 Apr 05 '20 at 12:12