If you guys have followed this tutorial: CRUD tutorial for NetBeans Platform 7.0, and tried to make it an Embedded JavaDB application based on the following tutorial: Embedded Database for NetBeans Platform CRUD, and you receive this “Table/View does not exist.“ error message, you need to edit a persistence.xml file as follows.
After creating entity classes from database, edit a persistence.xml file by adding:
<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
into the file within the existing <properties></properties> tags as shown below. (Notes: add the above line to persistence.xml before you create a dist folder).
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:derby:CustDB;create=true"/>
<property name="javax.persistence.jdbc.password" value="app"/>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver"/>
<property name="javax.persistence.jdbc.user" value="app"/>
<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
<property name="eclipselink.logging.level" value="INFO"/>
</properties>
Next, you just do the “Clean and Build All” to create a “dist” folder containing a “.jar” file. The .jar file will then be used for the CustomerLibrary wrapper module.
In my understanding, the reason is that the create=true property in the connection string URL, jdbc:derby:CustDB;create=true, will only create a new database, but does not create tables.
In addition, when making a connection using Services tab, a new database is created in $NetBeans_Home/.netbeans/7.0/derby. However, when creating a database from running the application, the database is created in $Project_Home or DBManager folder (Click the Files tab to see a newly-created database).
That’s why we still see tables existed when using Services tab, but the application issues “Table/View does not exist.” error message.
Cheers….
Greetings,
Since Services points to $NetBeans_Home/.netbeans/7.0/derby and not to the database in the project’s folder, do you know a way to manipulate the tables (other than programmatically)? I mean via the services or some other tool?
What if the database exists and it is already in the project’s folder and not in the derby default. How can you specify another database directory? I am trying something like jdbc:derby:file:/home/user/dbname but it does not work. Is it not possible to modify an existing embedded database via netbeans?
Sorry. I don’t know about that. Maybe, you need to look at the Netbeans configuration.
Thank you so much for this article. I was about to give up on the NB Platform and embedded Derby after wrestling with this issue for days.
Mr.TextMiner, the solution given by you to resolve the problem of ‘Table/view does not exist’ is not working..
I had wasted about my one week working on java derby. I got success in using derby network driver but still failed to use derby EmbeddedDriver because of error “Table/View ‘TableName’ does not exist”. Please, give a solution..
waiting for your rply…
I am not sure what you did. The only difference between my post and the tutorial is adding “property name” element for drop-and-create-tables to the persistence.xml file. Did you exactly follow the Netbeans IDE tutorial?
Hi, Mr.TextMinert
Please help me…I am waiting for your rply..
I think that I had exactly followed the Netbeans IDE tutorial.
Sir, I am following you only.
The steps I had taken are as follow:
I had created a table ‘college’ in sample database provided by netbeans. Then, saved its grab structure.
Maked a new Database with EmbeddedDriver of name “EmbDatabase;create=true” with user “APP” and password “app”. Then, recreate the table in EmbDatabase using the grab structure of college table. Then, create a Database Schema under persistence from NewFile wizard and a entity class from DatabaseSchema. Then, i had edit the persistence.xml file as described by you.
I had also added the derby.jar and derbytools.jar in the library of my project.
Still I am getting the error: Table/View ‘APP.COLLEGE’ does not exist.
Here is the code:-
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
query = jTextField1.getText();
try
{
ConnectMe();
}
catch(Exception e)
{
System.out.println(“exception in actionPerformed method of button 1 is: “+e);
}
}
public void ConnectMe() throws Exception
{
try
{
Class.forName(“org.apache.derby.jdbc.EmbeddedDriver”).newInstance();
Connection con = DriverManager.getConnection(“jdbc:derby:EmbDatabase;create=true”, “APP”, “app”);
Statement stmt = con.createStatement();
stmt.executeUpdate(query);
stmt.close();
con.close();
DriverManager.getConnection(“jdbc:derby:EmbDatabase;shutdown=true”);
}
catch(SQLException e)
{
System.out.println(“Exception in ConnectMe method is: “+e);
}
}
This is the copy of my persistence.xml file (after editting):-
org.eclipse.persistence.jpa.PersistenceProvider
DatabasePackage.College
Please Sir, help me….
copy of persistence.xml after editting:-
org.eclipse.persistence.jpa.PersistenceProvider
DatabasePackage.College
Please, someone tell me what to do…..