Changing the system-wide properties programmatically

You can set properties programmatically -- either in application code before booting the Derby driver or as a command-line option to the Java??? Virtual Machine (JVM) when booting the application that starts up Derby. When you set properties programmatically, these properties persist only for the duration of the application. Properties set programmatically are not written to the file or made persistent in any other way by Derby.

Note: Setting properties programmatically works only for the application that starts up Derby; for example, for an application in an embedded environment or for the application server that starts up a server product. It does not work for client applications connecting to a server that is running.

You can set properties programmatically in the following ways:

As a parameter to the JVM command line

You can set system-wide properties as parameters to the JVM command line when you start up the application or framework in which Derby is embedded. To do so, you typically use the -D option. For example:

java -Dderby.system.home=C:\home\Derby\ JDBCTest

Using a Properties object within an application or statement

In embedded mode, your application runs in the same JVM as Derby, so you can also set system properties within an application using a Properties object before loading the Derby JDBC driver. The following example sets derby.system.home on Windows.

Properties p = System.getProperties();
p.setProperty("derby.system.home", "C:\databases\sample");
Note: If you pass in a Properties object as an argument to the DriverManager.getConnection call when connecting to a database, those properties are used as database connection URL attributes, not as properties of the type discussed in this section. For more information, see Connecting to databases and Working with the database connection URL attributes as well as the Derby Reference Manual.
Related concepts
Changing the system-wide properties by using the file
Verifying system properties