Reputation: 67
I have tried to run some java class InsertApp which should push into existing table MYTABELLE22 a few rows. I'm getting from console Exception that table doesn't exist.
import java.sql.*;
public class InsertApp {
public static void main(String [] args) {
Connection con = null;
try {
con = DriverManager.getConnection(
"jdbc:derby:/Users/apolit/DerbyDatenbank;create=true");
Statement sta = con.createStatement();
// insert 3 rows
int count = 0;
int c = sta.executeUpdate("INSERT INTO MyTabelle22"
+ " (ID, MYKEY, CONTENT)"
+ " VALUES (1, 1, 'Bellevue')");
count = count + c;
c = sta.executeUpdate("INSERT INTO MyTabelle22"
+ " (ID, MYKEY, CONTENT)"
+ " VALUES (2, 2, 'Hull')");
count = count + c;
c = sta.executeUpdate("INSERT INTO MyTabelle22"
+ " (ID, MYKEY, CONTENT)"
+ " VALUES (3, 2, 'W. York')");
count = count + c;
System.out.println("Number of rows inserted: "+count);
sta.close();
con.close();
} catch (Exception e) {
System.err.println("Exception: "+e.getMessage());
}
}
}
Upvotes: 0
Views: 82
Reputation: 1454
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.
If 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 them 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.
Upvotes: 1