Applications must connect to an UltraLiteJ database before operations can be performed on the data. This section explains how to create or connect to a database with a specified password.
A Configuration is used to create and connect to a database. There are several different implementations of a Configuration provided in the API. A unique implementation exists for every type of database store supported by UltraLiteJ. Each implementation provides a set of methods used to configure the database store.
RIM object stores Supported with a ConfigObjectStore. See ConfigObjectStore interface (Java ME BlackBerry only).
Record stores Supported with a ConfigRecordStore. See ConfigRecordStore interface (Java ME only).
File system stores Supported with a ConfigFile. See ConfigFile interface.
Non-persistent stores Supported with a ConfigNonPersistent. See ConfigNonPersistent interface.
Internal flash and SD card stores Supported with a ConfigFileME. See ConfigFileME interface (BlackBerry only).
Transactions Transactions must be committed to the database using the commit method of the Connection. They can be rolled back using the rollback method.
Prepared SQL statements Methods are provided by the PreparedStatement interface to handle SQL statements. A PreparedStatement can be created using the prepareStatement method of the Connection.
Synchronization A set of objects governing MobiLink synchronization is accessed from the Connection.
You can not create a new UltraLiteJ database directly using Sybase Central or UltraLite command line utilities. An UltraLite database can be converted into an UltraLiteJ database using the ulunload and uljload utilities. An UltraLiteJ database created using uljload or a Java SE application can be deployed to a BlackBerry device by copying the database to an SD card or transferring it from MobiLink using the file transfer mechanism.
Create a new Configuration that references the database name and is appropriate for your platform.
In the following examples, config is the name of the Configuration object and DBname.ulj is the name of the new database.
For Java ME BlackBerry devices:
ConfigObjectStore config = DatabaseManager.createConfigurationObjectStore("DBname.ulj"); |
ConfigFileME config = DatabaseManager.createConfigFileME( "file:///store/home/user/DBname.ulj" ); |
ConfigFileME config = DatabaseManager.createConfigFileME( "file:///SDCard/DBname.ulj" ); |
For all other Java ME devices:
ConfigRecordStore config = DatabaseManager.createConfigurationRecordStore("DBname.ulj"); |
For Java SE devices:
ConfigFile config = DatabaseManager.createConfigurationFile("DBname.ulj"); |
Alternatively, you can create a non-persistent database Configuration, which is supported by all platforms:
ConfigNonPersistent config = DatabaseManager.createConfigurationNonPersistent("DBname.ulj"); |
Set a new database password using the setPassword method:
config.setPassword("my_password"); |
Create a new Connection:
Connection conn = DatabaseManager.createDatabase(config); |
The createDatabase method creates the database and returns a Connection to it. After this method is called, you can execute SQL statements to create the tables and indexes for your application but you can not change the name, password, or page size of the database.
An UltraLiteJ database must already exist on the client device before you can connect to it.
Create a new Configuration that references the name of the database and is appropriate for your platform.
In the following examples, config is the name of the Configuration object and DBname.ulj is the name of the database.
For Java ME BlackBerry devices:
ConfigObjectStore config = DatabaseManager.createConfigurationObjectStore("DBname.ulj"); |
ConfigFileME config = DatabaseManager.createConfigFileME( "file:///store/home/user/DBname.ulj" ); |
ConfigFileME config = DatabaseManager.createConfigFileME( "file:///SDCard/DBname.ulj" ); |
For all other Java ME devices:
ConfigRecordStore config = DatabaseManager.createConfigurationRecordStore("DBname.ulj"); |
For Java SE devices:
ConfigFile config = DatabaseManager.createConfigurationFile("DBname.ulj"); |
Alternatively, you can connect to a non-persistent database Configuration, which is supported by all platforms:
ConfigNonPersistent config = DatabaseManager.createConfigurationNonPersistent("DBname.ulj"); |
Specify the database password using the setPassword method:
config.setPassword("my_password"); |
Create a new Connection:
Connection conn = DatabaseManager.connect(config); |
The connect method finalizes the database connection process. If the database does not exist, an error is thrown.
A Connection object is disconnected from the database when the release method is called. The database is closed when all connections for a database have been released.
See release method.
Discuss this page in DocCommentXchange.
|
Copyright © 2010, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.0 |