| View previous topic :: View next topic |
| Author |
Message |
Sinsecato
Joined: 16 Feb 2010 Posts: 1
|
Posted: Wed Feb 17, 2010 3:22 pm Post subject: Embedded Derby Server won't Start Outside Netbeans |
|
|
I'm creating a database to use at my Screen Printing shop. I'm not very good at Java programming, but i've been able to follow the "Cars Database" tutorial and modify it to work for me. Now i'm trying to deploy this app outside of Netbeans. I've downloaded the Derby .bin file package, set up my environment variables, etc.
I've gotten to the point where i can run my App outside of NetBeans, but only if i use the command prompt to start the Derby Server first (by navigating to the directory of my App and then typing "startNetworkServer"). I have put the database files (Price List) in that same folder (PriceQuoteApp). My understanding is that using the Embedded Derby Server method my App should automatically start the Derby Network Server when it is run. The code i found to use for this is:
try {
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
} catch (ClassNotFoundException ex) {
System.out.println(ex);
}
try {
Connection con = DriverManager.getConnection("jdbc:derby:Price List;user=MyUserID;password=MyPassword");
} catch (SQLException ex) {
System.err.println(ex);
}
As far as i've been able to figure out this should start the server. I'm pretty much at a loss as to how to proceed. As I said the App runs if i've manually started the Derby Server through the Command Prompt (i run Windows XP by the way). I've read alot of forum posts to get as far as i've gotten, and have tried several variations of the Connection string (jdbc:derby://localhost:1527/Price List, and some others). Maybe I'm missing a line of code? |
|
| Back to top |
|
 |
Javier.Ortiz Posted via mailing list.
|
Posted: Wed Feb 17, 2010 5:40 pm Post subject: Embedded Derby Server won't Start Outside Netbeans |
|
|
I also do this before trying to start Derby:
private void setDBSystemDir() {
// Establish the db system directory: <userhome>/.hims/
String userHomeDir = System.getProperty("user.home", ".");
String systemDir = userHomeDir + "/.hims";
// Set the db system directory.
System.setProperty("derby.system.home", systemDir);
}
Here I'm seeting it to the user's home but you can set it somewhere else.
Keep in mind that this is for embedded Derby.
Javier A. Ortiz Bultr |
|
| Back to top |
|
 |
likesjava
Joined: 18 Dec 2009 Posts: 29
|
Posted: Sat Feb 27, 2010 6:03 pm Post subject: Cannot start embedded derby without NB |
|
|
I'm in a similar boat.
Using the embedded derby driver with "create=true" argument.
I can run from the jnlp file, but ONLY if NB (6.8 ) is running and has the Java DB started.
Is anyone else having this issue?
Also I can only run with a URL including local host. Plain old HOST = "jdbc:derby: <with db name etc> can never see the DB.
Is it normally this hard to set this up? I can only imagine its worse when deployed. |
|
| Back to top |
|
 |
javydreamercsw
Joined: 22 Jun 2009 Posts: 456
|
Posted: Sun Feb 28, 2010 8:04 pm Post subject: Embedded Derby Server won't Start Outside Netbeans |
|
|
Did you state the derby home property?
I have it working. I think I posted code in this thread.
On Sat, Feb 27, 2010 at 12:04 PM, likesjava <address-removed ([email]address-removed[/email])> wrote:
| Quote: | I'm in a similar boat.
Using the embedded derby driver with "create=true" argument.
I can run from the jnlp file, but ONLY if NB (6. is running and has the Java DB started.
Is anyone else having this issue?
Also I can only run with a URL including local host. Plain old HOST = "jdbc:derby: <with db name etc) can never see the DB.
Is it normally this hard to set this up? I can only imagine its worse when deployed.
|
|
|
| Back to top |
|
 |
likesjava
Joined: 18 Dec 2009 Posts: 29
|
Posted: Tue Mar 02, 2010 4:19 am Post subject: |
|
|
Sorry for the late reply.
yes I tried the code mentioned. I had to modify the home dir as follows:
| Code: | | String systemDir = userHomeDir + "/.netbeans-derby"; |
which begs the question what happens if this is deployed to another machine? How can this be made portable?
But even worse, if I connect using HOST = "jdbc:derby:", I get error:
Connection authentication failure occurred. Reason: Invalid authentication..
However if I use HOST = "jdbc:derby://localhost:1527/", it at least connects.
But what happens if local host....is deployed ? I cannot seem to just run HOST = "jdbc:derby:".... |
|
| Back to top |
|
 |
javydreamercsw
Joined: 22 Jun 2009 Posts: 456
|
Posted: Tue Mar 02, 2010 12:51 pm Post subject: Embedded Derby Server won't Start Outside Netbeans |
|
|
Just make sure to check the dir exits on the machine, if not just create it with the File API. I guess you are loading the driver (that starts the server) after setting the location.
After doing that I use the "jdbc:derby:<db name>" without issues.
On Mon, Mar 1, 2010 at 10:20 PM, likesjava <address-removed ([email]address-removed[/email])> wrote:
| Quote: | Sorry for the late reply.
yes I tried the code mentioned. I had to modify the home dir as follows:
Code:
String systemDir = userHomeDir + "/.netbeans-derby";
which begs the question what happens if this is deployed to another machine? How can this be made portable?
But even worse, if I connect using HOST = "jdbc:derby:", I get error:
Connection authentication failure occurred. Reason: Invalid authentication..
However if I use HOST = "jdbc:derby://localhost:1527/", it at least connects.
But what happens if local host....is deployed ? I cannot seem to just run HOST = "jdbc:derby:"....
|
|
|
| Back to top |
|
 |
likesjava
Joined: 18 Dec 2009 Posts: 29
|
Posted: Tue Mar 02, 2010 1:12 pm Post subject: |
|
|
Ji Javy,
You posted "Just make sure to check the dir exits on the machine, if not just create it with the File API. I guess you are loading the driver (that starts the server) after setting the location. "
Actually I am loading the driver BEFORE setting the connection - does that matter?
As for making sure the directory exists on the machine - at this point we are talking about my own machine, where the directory's are a known factor. I don't really see an answer yet to what I asked in the previous post.
Could anyone with a working example of of an embedded DerbyDB that can autostart AND that can be deployed to another machine with a different file structure possibly post an example? Might save a lot of typing.
Thanks much |
|
| Back to top |
|
 |
Javier.Ortiz Posted via mailing list.
|
Posted: Tue Mar 02, 2010 7:40 pm Post subject: Embedded Derby Server won't Start Outside Netbeans |
|
|
This is how I do it (working example)
In the module's ComponentOpen method:
@Override
@SuppressWarnings("static-access")
public void componentOpened() {
//SCR 1743: Add database support
setDBSystemDir();
//SCR 2394: Switch to embedded database if something goes wrong.
OutputHandler.setStatus("Connecting to database. Please wait...");
try {
DataBaseManager.get("HIMSPU");
} catch (Error e) {
log(e.getLocalizedMessage());
//Something's wrong with the main database. Use the embedded one
DataBaseManager.get("HIMSDerbyPU");
}
...
The setDBSystemDir(); just sets the derby home.
The database manager does the rest. here's what is called at this point:
public static DataBaseManager get(String pu) {
//SCR 2238: Allow to change the connection
if (instance == null ||
(instance!=null && !instance.getPersistenceUnitName().equals(pu))) {
instance = new DataBaseManager(pu);
getEntityManager();
puName=pu;
}
return instance;
}
And JPA does the rest.
Javier A. Ortiz Bultr |
|
| Back to top |
|
 |
likesjava
Joined: 18 Dec 2009 Posts: 29
|
Posted: Tue Mar 02, 2010 9:30 pm Post subject: |
|
|
Hi Javier,
Thanks for your patience - I am in need of a little more
The code you have above is so different from what I am doing that I am not sure how to apply it. (But thank you for posting it).
Perhaps I should post what I have and see if something seems obvious to you:
| Code: | import java.sql.*;
import java.util.*;
public class ClassQuery {
private static final String DB = "JapaneseWords",
TABLE_NAME = "MAIN",
//HOST = "jdbc:derby://localhost:1527/",
HOST = "jdbc:derby:",
ACCOUNT = "APP",
PASSWORD = "myPWD",
DRIVER = "org.apache.derby.jdbc.EmbeddedDriver";
public static String queryResult;
public static Integer numOfcolums;
private static void setDBSystemDir() {
// Establish the db system directory: <userhome>/.hims/
String userHomeDir = System.getProperty("user.home", ".");
String systemDir = userHomeDir + "/.netbeans-derby";
// Set the db system directory.
System.setProperty("derby.system.home", systemDir);
}
public static String GetRS(String sqlQuery) {
//setDBSystemDir(); //testing Javier's idea
Properties props = new Properties();
props.setProperty("APP", ACCOUNT);
props.setProperty("password", PASSWORD);
String res = "";
try {
// load driver and prepare to access
Class.forName(DRIVER).newInstance();
// System.setSecurityManager(null);
Connection con = DriverManager.getConnection(
HOST + DB + ";create=true", props); |
Please note that if I run from the IDE as above, the database is found but I get a authentication error. If I switch to using localhost it connects. (But I fear this is wrong for a standalone embedded derby app). And using localhost but running outside the IDE gets an authentication error.
If I use the code you provided earlier, it cant find the database, so its commented.
Currently, I have the DB in the project folder, and its jar file is in the dist/lib folder.
Does anything here suggest why I am getting an authentication error?
Thanks in advance! |
|
| Back to top |
|
 |
Javier.Ortiz Posted via mailing list.
|
Posted: Tue Mar 02, 2010 9:44 pm Post subject: Embedded Derby Server won't Start Outside Netbeans |
|
|
Is there a chance I can have the source and try it by myself?
I see the following:
You are not setting the derby home so it'll assume the default (user.di)
Maybe there's nothing there. When you run it from Netbeans probably Netbeans starts the server and sets up the variable properly.
If Netbeans starts it with a certain user and password. That would explain the login issues.
In my case I use a string like this one:
jdbc:derby:<db name>;create=true (I might be wrong)
Javier A. Ortiz Bultr |
|
| Back to top |
|
 |
likesjava
Joined: 18 Dec 2009 Posts: 29
|
Posted: Tue Mar 02, 2010 10:14 pm Post subject: |
|
|
Hi Javier,
I would be most grateful if you would be willing to look at the source.
I will slim the database down to a few entries of course. How can I get it to you? Can you PM with with your email? I have been stuck on this issue for a while now - your getting my hopes up
Hopefully when we get it sorted, we can post the solution for others. |
|
| Back to top |
|
 |
likesjava
Joined: 18 Dec 2009 Posts: 29
|
Posted: Tue Mar 02, 2010 11:03 pm Post subject: |
|
|
PS,
Just saw that PMs are disabled on this board.
Hmm, how can I get these files to you Javier? |
|
| Back to top |
|
 |
likesjava
Joined: 18 Dec 2009 Posts: 29
|
Posted: Wed Mar 03, 2010 1:11 pm Post subject: |
|
|
After a little more reading....
I may have failed to understand the whole concept of deploying an embedded derby db. Looking through the samples, they always demo creating tables on the fly in a new DB created by the app.
Thats not what I am doing.
I have an existing derby database that I want to deploy and run....
hmmm. Will post back if I get this figured out. |
|
| Back to top |
|
 |
Javier.Ortiz Posted via mailing list.
|
Posted: Wed Mar 03, 2010 9:40 pm Post subject: Embedded Derby Server won't Start Outside Netbeans |
|
|
If you sent them to my personal email I should get them sometime tonight. I won't be able to take a look until tomorrow if that's the case.
Javier A. Ortiz Bultr |
|
| Back to top |
|
 |
Javier.Ortiz Posted via mailing list.
|
Posted: Wed Mar 03, 2010 10:21 pm Post subject: Embedded Derby Server won't Start Outside Netbeans |
|
|
I though you were using JPA which would create the database tables if configured to do so. That plus using create=true will make the database available.
Javier A. Ortiz Bultr |
|
| Back to top |
|
 |
|