You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Philippe Lamote <ph...@mac.com> on 2006/03/22 12:37:02 UTC

running Mode config

Hi List,

I think I have a typical "development" setup config question for Derby.
In "production", obviously running Derby in embedded mode has the  
advantage it can run in the same JVM, which is better, security/ 
performance wise, that over the network.
BUT during development one often wishes to follow, with an external  
client (like DBVisualizer, Aqua Data Studio - both of which are Java  
Apps), what the code does to the DB.
(and possibly interact)

Therefore, what I tried is:
1/ In an application properties file I keep the default parameters  
for Derby. (Default = in production e.g. ConnDriver = the embedded  
driver)
But it also keeps a "runningMode"="development" | "production" value.  
If its value is "development", in the application init method, some  
values are overwritten: cf 2/

2/ In the App init method is an if-clause thet sets/overwrites these  
settings in case the "runningMode" is "development":

	- ConnURL = "jdbc:derby://localhost:1527/"+ derbyHome;
	- System.getProperties().put("derby.drda.startNetworkServer","true");
	- added: try{
			NetworkServerControl server = new NetworkServerControl 
(InetAddress.getByName("localhost"),1527);
			server.start(null);}
			catch (Exception e) { e.printStackTrace();
			}
	- driver to use is set to org.apache.derby.jdbc.ClientDriver

 From the Derby doc I understand firing off the Server keep it  
running, also beyond main(), until you manually fire a shutdown command.
--> I thought this would allow me to connect via a Java DB app and  
never having to do any extra config apart from setting this  
runningMode variable in the properties file. (or with Spring, as you  
wish)

Yet , I get this exception:

An error occured while establishing the connection.
    Type: org.apache.derby.client.am.DisconnectException   Error  
Code: -4499
Message:
    java.security.PrivilegedActionException : Error opening socket to  
server localhost on port 1527 with message : null

(using the ClientDriver, Login/Passw = APP/) I tried providing a  
password anyway ("key") and also this passw in the DB viewer app,  
without any effect though.

So the questions I have, are:
- I feel setting "derby.drda.startNetworkServer" to "true" AND  
issuing the "new NetworkServerControl(...)" are doing twice the same  
and that I can (as in: would better!) drop one of them. Is this correct?
- Is the driver the app itself has to use to connect to the DB, after  
firing the Network Server: the ClientDriver, or the EmbeddedDriver?  
The doc got me confused about this.
- Any suggestions as to how to make this work properly? :-) It looks  
like either the Server has shutdown already when I use the DB app  
(although the server was started and not shutdown that I know of), or  
that I need a password (thought this was never necessary, unless you  
explicitely set "authentication" somewhere)

Thanks for suggestions,
Philippe



Password protection

Posted by Grégoire Dubois <gr...@online.fr>.
Hi all,

Would somebody know how a user password is protected in derby ?

Thank you very much.

Regards,
Greg.

Re: running Mode config

Posted by Kristian Waagan <Kr...@Sun.COM>.
Philippe Lamote wrote:
> Hi List,
>
> I think I have a typical "development" setup config question for Derby.
> In "production", obviously running Derby in embedded mode has the 
> advantage it can run in the same JVM, which is better, 
> security/performance wise, that over the network.
> BUT during development one often wishes to follow, with an external 
> client (like DBVisualizer, Aqua Data Studio - both of which are Java 
> Apps), what the code does to the DB.
> (and possibly interact)
>
> Therefore, what I tried is:
> 1/ In an application properties file I keep the default parameters for 
> Derby. (Default = in production e.g. ConnDriver = the embedded driver)
> But it also keeps a "runningMode"="development" | "production" value. 
> If its value is "development", in the application init method, some 
> values are overwritten: cf 2/
>
> 2/ In the App init method is an if-clause thet sets/overwrites these 
> settings in case the "runningMode" is "development":
>
>     - ConnURL = "jdbc:derby://localhost:1527/"+ derbyHome;
>     - System.getProperties().put("derby.drda.startNetworkServer","true");
>     - added: try{
>             NetworkServerControl server = new 
> NetworkServerControl(InetAddress.getByName("localhost"),1527);
>             server.start(null);}
>             catch (Exception e) { e.printStackTrace();
>             }
>     - driver to use is set to org.apache.derby.jdbc.ClientDriver

Hi Philippe,

I think the code above starting the network server is the cause for the 
exception, or the connection string you use.
What do the 'InetAddress.getByName("localhost")' command return? If it 
is neither "localhost" nor "127.0.0.1", the connection string 
"jdbc:derby://localhost:1527/..." will not work.
Say the hostnamed returned is "philippe", then you must use the 
connection string "jdbc:derby://philippe:1527/...".
These observations concern the client driver, not the embedded driver.

Double check what the network server is started with, or just hard-code 
"localhost" to see if that fixes the problem. If the problem goes away, 
you can adjust your code accordingly.


--
Kristian

>
> From the Derby doc I understand firing off the Server keep it running, 
> also beyond main(), until you manually fire a shutdown command.
> --> I thought this would allow me to connect via a Java DB app and 
> never having to do any extra config apart from setting this 
> runningMode variable in the properties file. (or with Spring, as you 
> wish)
>
> Yet , I get this exception:
>
> An error occured while establishing the connection.
>    Type: org.apache.derby.client.am.DisconnectException   Error Code: 
> -4499
> Message:
>    java.security.PrivilegedActionException : Error opening socket to 
> server localhost on port 1527 with message : null
>
> (using the ClientDriver, Login/Passw = APP/) I tried providing a 
> password anyway ("key") and also this passw in the DB viewer app, 
> without any effect though.
>
> So the questions I have, are:
> - I feel setting "derby.drda.startNetworkServer" to "true" AND issuing 
> the "new NetworkServerControl(...)" are doing twice the same and that 
> I can (as in: would better!) drop one of them. Is this correct?
> - Is the driver the app itself has to use to connect to the DB, after 
> firing the Network Server: the ClientDriver, or the EmbeddedDriver? 
> The doc got me confused about this.
> - Any suggestions as to how to make this work properly? :-) It looks 
> like either the Server has shutdown already when I use the DB app 
> (although the server was started and not shutdown that I know of), or 
> that I need a password (thought this was never necessary, unless you 
> explicitely set "authentication" somewhere)
>
> Thanks for suggestions,
> Philippe
>
>


Re: running Mode config

Posted by John Embretsen <Jo...@Sun.COM>.
Hi Philippe,

I think you describe an interesting use case which confirms the fact
that the Derby documentation certainly could be better in a lot of
areas. I actually think I learned something :) while trying to figure out
the proper answers to your questions; see below...

Wednesday, March 22, 2006, 12:37:02 PM CET, Philippe Lamote wrote:

<snip details>

> - I feel setting "derby.drda.startNetworkServer" to "true" AND
> issuing the "new NetworkServerControl(...)" are doing twice the same  
> and that I can (as in: would better!) drop one of them. Is this correct?

Yes, you can drop one or the other, and it will still work.

By the way, a note from looking at your code snippet:
It is recommended that you set system properties by using the
System.setProperty(...) method instead of the put(...) method you are
using (see e.g. javadoc for java.util.Properties). So, instead of

System.getProperties().put("derby.drda.startNetworkServer","true");

you should use

System.setProperty("derby.drda.startNetworkServer", "true");

> - Is the driver the app itself has to use to connect to the DB, after  
> firing the Network Server: the ClientDriver, or the EmbeddedDriver?  
> The doc got me confused about this.

AFTER starting the Network Server, the app which started the server can
use either driver for accessing the database. Other apps (running in
other JVMs) MUST use the client driver to connect to the DB.

See also the Derby tutorial at
http://db.apache.org/derby/papers/DerbyTut/ns_intro.html#Embedded+Server

What I did _not_ find clearly stated in the docs or the tutorial,
however, is how you should start derby when using the property
derby.drda.startNetworkServer=true. The admin guide says

"When you set derby.drda.startNetworkServer, the Network Server will
automatically start when you start Derby."

Now, what probably should have been included in the manual and the
tutorial, is that you start Derby in this case by loading the embedded
driver:

Class.forName("org.apache.derby.jdbc.EmbeddedDriver");

And voila, you have a running "embedded server".

You can then create connections using both the embedded driver _and_ the
client driver in that same application.

You can also, after starting the server as shown above, access the
Network Server from _other_ JVMs (external clients) by using the client
driver, as long as the JVM which started the server is still running.

> - Any suggestions as to how to make this work properly? :-) It looks  
> like either the Server has shutdown already when I use the DB app  
> (although the server was started and not shutdown that I know of), or  
> that I need a password (thought this was never necessary, unless you  
> explicitely set "authentication" somewhere)

I am not sure from where you are trying to access the derby server (same
JVM? Another JVM?). But the bottom line is that the server shuts down
when you explicitly tell it to do so, or when the JVM which launched the
server exits, whichever comes first.

No username/password necessary by default.

Hope this helps!


-- 
John