0

I read a lot of posts like: querying embedded database in netbeans using derby

But still I'm having trouble to understand embedded databases.

1) I create a Derby database on Netbeans and I can create tables, link the database to a form and submit the data and update the records with no problem.

2) The problem arises when I want to make the program portable. I apply Clean and Build, then copy the dist folder and also copy the libraries, database, etc ... but when running the program does not recognize the database

3) I read in several places that it is appropriate that the database is created by code using something like

String host = "jdbc: derby: // localhost: 1527 / EmployeesCreateTrue; create = true"

and not creating the database on Netbeans Service...

If I do this procedure with code the database is created but it does not appear or does not allow me to connect from NetBeans and I wish I could fix it to create tables from NetBeans and not from code.

4) I read manuals "how to import a database from Derby to NetBeans" and it doesn't work...

Question: What is the best way to create a database, tables and connect to NetBeans for the final application to be easily portable?

1) Create the database on Netbeans with the wizzard?

or

2) Just plain code on the application?

Community
  • 1
  • 1
fedeteka
  • 943
  • 1
  • 14
  • 33

3 Answers3

0

I don't understand precisely what you mean by "the database is created but it does not appear."

I think if you were to explain that precisely, the community could probably help you.

There are three common reasons for "table does not exist" when you think you've created the tables; I've explained those cases in this answer: Is it necessary to create tables each time you connect the derby database?

Please let us know more information about your situation so that we can help you better understand the behavior of your application.

Community
  • 1
  • 1
Bryan Pendleton
  • 16,128
  • 3
  • 32
  • 56
  • Hello Bryan, thanks for the answer. Excuse my poor english. If I create the database using code like "String host = "jdbc: derby: // localhost: 1527 / EmployeesCreateTrue; create = true"" the database is created, I can check this on the Windows directory of my Derby databases, but the database created is not listed on NetBeans - Services - JB, so I can't use NetBeans to create the schema and tables and populate data. That's my problem at this moment. – fedeteka Sep 24 '14 at 22:15
  • Thanks for clarifying! I can think of several possibilities: (1) Netbeans is using a different connection URL than your program is, or (2) Netbeans has to do some sort of "refresh" to see your newly created database. When you use Netbeans to connect to your database(s), what JDBC Connection URL do you give to Netbeans? – Bryan Pendleton Sep 24 '14 at 22:28
  • Hello Bryan, for the Databases Created on NetBeans de JDBC Connection URL is Display Nam: jdbc:derby://localhost:1527/Employees [root on ROOT] Database URL: jdbc:derby://localhost:1527/Employees Driver: apache_derby_net Driver class: org.apache.derby.jdbc.ClientDriver I dont find any Refresh or Update option, so I think when I open Netbeans the Derby directory is scanned searching for databases. I dont know why the one created with pure code is not listed. – fedeteka Sep 25 '14 at 21:18
  • The database that is not listed on NetBeans was created with code like: String host = "jdbc:derby://localhost:1527/EmployeesCreateTrue; create=true"; So, seems that I used the right sintaxis. Thanks for any support. – fedeteka Sep 25 '14 at 21:19
  • I'm not sure if this is the problem, but "jdbc:derby://localhost:1527/Employees" does not name the same database as "jdbc:derby://localhost:1527/EmployeesCreateTrue; create=true". One database is named "Employees"; the other is named "EmployeesCreateTrue". – Bryan Pendleton Sep 26 '14 at 02:24
  • Employees is the database created on NetBeans and works fine. EmployeesCreateTrue is the other one created with code and the one I cant open on NetBeans. :( – fedeteka Sep 26 '14 at 11:05
0

I'm not 100% sure if this is your problem, but a lot of problems people seem to have with Netbeans and Derby seems to come from the fact that they don't set derby.system.home explicitly. When you don't, Derby stores databases in the current directory, and that is likely different when working in the IDE, either in the Services tab, or your own code, than when you execute your app's jar as a standalone program. So the advice (which you will also find in the manual) is: always set derby.system.home. An alternative would be to use full paths to the databases, but that rarely works well for a real application that is deployed on different machines.

Dyre
  • 547
  • 1
  • 3
  • 2
  • Hello Dyre, thanks for the tip. I'm using Windows 7. I need to install Derby also on Windows? I mean, on this case, if the JAR need Derby installed on the system then is not full embedded and portable no? My actual URL is: jdbc: derby: // localhost: 1527 / Employees I will try with http://db.apache.org/derby/docs/10.0/manuals/tuning/perf14.html another configuration. "Derby JDBC driver. The following example sets derby.system.home on Windows. Properties p = System.getProperties(); p.put("derby.system.home", "C:\databases\tours");" – fedeteka Sep 29 '14 at 14:51
0

I had the same problem --had the derby db in the services but the netbeans coded programs didn't access it. I solved it by adding the derby database (copy paste) to the package in the Files section. I use Windows 7. Once I did that, I was able use multiple tables (before netbeans just ignored secondary tables and only allowed me to use the primary table).