Java DB

Apache Derby

Derby Server and Administration Guide

Derby Getting Started
Derby Reference Manual
Derby Developer's Guide
Derby Performance Tuning
Derby Server and Admin Guide
Derby Tools and Utilities
Derby Server and Admin Guide
-Part one: Derby Server Guide
-Derby in a multi-user environment
-Using the Network Server with preexisting Derby applications
-The Network Server and JVMs
-Installing required jar files and adding them to the classpath
-Starting the Network Server
-Shutting down the Network Server
-Obtaining system information
-Accessing the Network Server by using the network client driver
-Accessing the Network Server by using a DataSource object
-XA and the Network Server
-Using the Derby tools with the Network Server
-Differences between running Derby in embedded mode and using the Network Server
-Setting port numbers
-Managing the Derby Network Server
-Managing the Derby Network Server remotely by using the servlet interface
-Derby Network Server advanced topics
-Derby Network Server sample programs
-Part two: Derby Administration Guide
-Checking database consistency
-Backing up and restoring databases
-Replicating databases
-Logging on a separate device
-Obtaining locking information
-Reclaiming unused space

 

DataSource access examples

The following example uses org.apache.derby.jdbc.ClientDataSource to access the Network Server:

org.apache.derby.jdbc.ClientDataSource ds =
   new org.apache.derby.jdbc.ClientDataSource();
ds.setDatabaseName("mydb");
ds.setCreateDatabase("create");  
ds.setUser("user");  
ds.setPassword("mypass"); 

// The host on which Network Server is running
ds.setServerName("localhost");

// The port on which Network Server is listening
ds.setPortNumber(1527);

Connection conn = ds.getConnection(); 

Statement caching example

The following example uses org.apache.derby.jdbc.ClientConnectionPoolDataSource to access the Network Server and use JDBC statement caching:

org.apache.derby.jdbc.ClientConnectionPoolDataSource cpds = 
   new ClientConnectionPoolDataSource();

// Set the number of statements the cache is allowed to cache.
// Any number greater than zero will enable the cache.
cpds.setMaxStatements(20);

// Set other DataSource properties
cpds.setDatabaseName("mydb");
cpds.setCreateDatabase("create");
cpds.setUser("user");
cpds.setPassword("mypass"); 
cpds.setServerName("localhost");
cpds.setPortNumber(1527);

// This physical connection will have JDBC statement caching enabled.
javax.sql.PooledConnection pc = cpds.getPooledConnection();

// Create a logical connection.
java.sql.Connection con = pc.getConnection();

// Interact with the database.
java.sql.PreparedStatement ps = con.prepareStatement(
   "select * from myTable where id = ?");
...
ps.close(); // Inserts or returns statement to the cache
...
con.close();

// The next logical connection can gain from using the cache.
con = pc.getConnection();

// This prepare causes a statement to be fetched from the local cache.
PreparedStatement ps = con.prepareStatement(
   "select * from myTable where id = ?");
...

// To dispose of the cache, close the connection.
pc.close();
 

javadb@jdbcurl.com