I'm building a Java Application with an embedded database on Netbeans 7.2.1. For now, I'm able to establish a connection with the derby database through the following code:
Connection con = DriverManager.getConnection(
"jdbc:derby:database;create=true",
uName,
uPass);
However, I'm not able to execute queries on the tables of the database. After some research, I tried to execute the following code, but without success:
Statement stmt = con.createStatement();
ResultSet rs;
rs = stmt.executeQuery("SELECT descricao FROM fichas");
while (rs.next()) {
String s = rs.getString("descricao");
System.out.println(s);
}
I have two problems here. First, based on the search I do I should use Statement stmt as in the example above but netbeans gives me an error. To being able to execute the method "stmt.executeQuery()" that follows him I have to define statement as:
java.sql.Statement stmt = con.createStatement();
If I don't use it like this I can't pick the method "executeQuery". Second, even using this the query doesn't get executed. I get an error on the console:
java.sql.SQLSyntaxErrorException: Schema 'ADMIN_DATABASE' does not exist
Any hints how I can solve this? Thank you!
NEW UPDATES:
I was running some tests and here they are some new conclusions. If instead of creating the tables through the services panel of the netbeans, i run the code:
stmt.execute("create table test_table (name varchar(128))");
it works. The table is created and if i try again it gives the expected error that the table already exists. However, i look at the services panel, att the app embedded derby database and this 'test-table' is not there together it the others.
Adding to that, if i execute a select on that table it gives no schema error but in the others i created manually on the services panel it continues to give the error.
So, can anyone please explain what the difference is? Where the test_table
I created goes? What's the difference between this mode of creation and the one of creating the tables on derby? Why do I receive schema errors with ones and not with the others?
Sorry for so many questions but now I'm very confused. Thank you!