␡
- Derby: A Database for All Seasons
- What Is Derby?
- How to Use Derby
- Setting Up Your CLASSPATH
- Testing Your Setup
- Running Your First Derby Program
- Derby Application Components
- Derby Application Startup
- Loading the Derby Driver
- Database and Connection Creation
- Statement Creation
- Table Creation
- Table Access
- Shutdown
- Running the Code
Like this article? We recommend
Derby Application Startup
Listing 4 illustrates the command line argument parsing procedure.
Listing 4 Starting up the program
private void parseArguments(String[] args) { int length = args.length; for (int index = 0; index < length; index++) { if (args[index].equalsIgnoreCase("jccjdbcclient")) { framework = "jccjdbc"; driver = "com.ibm.db2.jcc.DB2Driver"; protocol = "jdbc:derby:net://localhost:1527/"; } if (args[index].equalsIgnoreCase("derbyclient")) { framework = "derbyclient"; driver = "org.apache.derby.jdbc.ClientDriver"; protocol = "jdbc:derby://localhost:1527/"; } } }
The program command line is java SimpleApp, so the above for loop doesn’t execute because the length is zero. This means that the variables: framework, driver, and protocol are all set to default values. These values are set in the public members, as illustrated in Listing 5.
Listing 5 Public member data
public String framework = "embedded"; public String driver = "org.apache.derby.jdbc.EmbeddedDriver"; public String protocol = "jdbc:derby:";
This means that the code in Listing 4 is bypassed. If you prefer, you can supply command-line parameters, but this is an optional step to make it easier to run the example code.