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.
Object stores Supported with a ConfigObjectStore.
Record stores Supported with a ConfigRecordStore.
Persistent file stores Supported with a ConfigFile.
Non-persistent stores Supported with a ConfigNonPersistent.
Transactions In the UltraLiteJ API, there is no AutoCommit mode. Each transaction must be followed by the commit method of the Connection. They can be rolled back with a rollback statement.
Prepared SQL statements Methods are provided to handle the SQL statement, which are executed from the Connection.
Synchronization A set of objects governing synchronization is accessed from the Connection.
Table operations UltraLiteJ database tables are accessed and maintained using methods of the Connection.
An UltraLiteJ database can only be created using the API. You can not create a new database using Sybase Central or the UltraLite command line utilities.
To create a database
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 supported by all platforms:
ConfigNonPersistent config = DatabaseManager.createConfigurationNonPersistent("DBname.ulj"); |
Set a new database password using the setPassword method.
The following example sets the password to my_password:
config.setPassword("my_password"); |
Create a new Connection using the following syntax:
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.
The UltraLiteJ database must already exist on the client device before you can connect to it.
To connect to an existing database
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 supported by all platforms with the following syntax:
ConfigNonPersistent config = DatabaseManager.createConfigurationNonPersistent("DBname.ulj"); |
Specify the database password using the setPassword method.
The following example assumes that the password is my_password:
config.setPassword("my_password"); |
Create a new Connection using the following code:
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 object and all properties associated with it.
Send feedback about this page via email or DocCommentXchange | Copyright © 2008, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.0 |