UltraLite User's Guide
Developing UltraLite Java Applications
Connecting to and configuring your UltraLite database
The generated UltraLite database code is in the form of a class that extends JdbcDatabase, which has a connect method that establishes a connection.
The following example illustrates typical code, for a generated database class called SampleDB:
try { SampleDB db = new SampleDB(); java.sql.Connection conn = db.connect(); } catch( SQLException e ){ // error processing here }
The generated database class is supplied on the UltraLite generator command line, using the -f
option.
If you wish to use a persistent database, the characteristics are specified on the connection as a Properties object. The following example illustrates typical code:
java.util.Properties p = new java.utils.Properties(); p.put( "persist", "file" ); p.put( "persistfile", "c:\\dbdir\\database.udb" ); SampleDB db = new SampleDB( p ); java.sql.Connection conn = db.connect( );
The Properties are used on the database constructor. You cannot change the persistence model of the database between connections.
The two properties specify that the database is persistent, and is stored in the file c:\dbdir\database.udb.
For more information on the properties you can specify in the URL, see UltraLite JDBC URLs.
For more information see Configuring the UltraLite Java database, and The generated database class.