Use the UltraLiteJ API with your Java application to create or connect to a database.
Prerequisites
An existing Java application for an Android or a BlackBerry smartphone that implements the UltraLiteJ API.
Create a new Configuration object that references the database name and is appropriate for your platform.
In the following examples, config is the Configuration object name and DBname is the database name.
For Android smartphones:
ConfigFileAndroid config = DatabaseManager.createConfigurationFileAndroid( "DBname.udb", getApplicationContext() ); |
For BlackBerry smartphones:
ConfigObjectStore config = DatabaseManager.createConfigurationObjectStore("DBname.ulj"); |
For Java SE platforms:
ConfigFile config = DatabaseManager.createConfigurationFile("DBname.ulj"); |
For any platform, you can create a non-persistent database Configuration object:
ConfigNonPersistent config = DatabaseManager.createConfigurationNonPersistent("DBname.ulj"); |
Set database properties using methods of the Configuration object.
For example, you can set a new database password using the setPassword method:
config.setPassword("my_password"); |
For Android smartphones, you can use the setCreationString and setConnectionString methods to set additional creation and connection parameters, respectively.
For more information about creation and connection parameters, see:
Create a Connection object to create or connect to the database:
For example, the following code creates a new database:
Connection conn = DatabaseManager.createDatabase(config); |
The DatabaseManager.createDatabase method creates the database and returns a connection to it.
In the above example, the following code is used to connect to an existing database:
Connection conn = DatabaseManager.connect(config); |
The connect method finalizes the database connection process. If the database does not exist, an error is thrown.
![]() |
Discuss this page in DocCommentXchange.
|
Copyright © 2014, SAP AG or an SAP affiliate company. - SAP Sybase SQL Anywhere 16.0 |