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 different set of methods used to access the database store.
RIM object stores Supported with a ConfigObjectStore.
Record stores Supported with a ConfigRecordStore.
File system stores Supported with a ConfigFile.
Non-persistent stores Supported with a ConfigNonPersistent.
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.
Table operations UltraLiteJ database tables are accessed and maintained using methods provided by the Connection interface.
An UltraLiteJ database can only be created using the API. You can not create a new database using Sybase Central or UltraLite command line utilities.
Create a new Configuration that references the database name.
The proper syntax depends on the Java platform and the client device. In the following examples, config is the name of the Configuration object and DBname.ulj is the name of the new database.
For J2ME BlackBerry devices:
ConfigObjectStore config = DatabaseManager.createConfigurationObjectStore("DBname.ulj"); |
For all other J2ME devices:
ConfigRecordStore config = DatabaseManager.createConfigurationRecordStore("DBname.ulj"); |
For J2SE 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 finalizes the database creation process and connects to the database. After this method is called, you can perform schema and data operations but you can no longer 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.
The proper syntax depends on the Java platform and the client device. In the following examples, config is the name of the Configuration object and DBname.ulj is the name of the database.
For J2ME BlackBerry devices:
ConfigObjectStore config = DatabaseManager.createConfigurationObjectStore("DBname.ulj"); |
For all other J2ME devices:
ConfigRecordStore config = DatabaseManager.createConfigurationRecordStore("DBname.ulj"); |
For J2SE 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.
Use the release method of the DatabaseManager class to disconnect from the UltraLiteJ database. The release method closes the Connection and all properties associated with it.
Discuss this page in DocCommentXchange. Send feedback about this page using email. |
Copyright © 2009, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.1 |