- Connecting to ASA
- Querying the Database
- Java UltraLite Development
- Conclusion
Java UltraLite Development
As explained in Part 1 of this tutorial, UltraLite is the "lite" deployment option for SQL Anywhere Studio 8.0 applications. UltraLite databases are single files and the UltraLite runtime database engine is actually compiled into your application (as opposed to ASA, which exists as a separate application and communicates with your Java application using a TCP/IP socket). Unlike ASA, UltraLite databases do not support advanced concepts such as stored procedures, triggers, internal security, and Java in the database. An UltraLite database file can be built in one of two ways:
Using the ulinit to generate an UltraLite schema based on an existing ASA database schema
-
Using the included UltraLite Schema Painter utility (see Figure 1) to build a new schema from scratch
Figure 1 UltraLite Schema Painter utility.
Stepping through the UltraLite Schema Painter utility, you'll notice that several of the ASA datatypes aren't available in UltraLiteincluding VARCHAR and TEXT (two data types we used to create our mobile_sales.db database). After you create the desired schema named mobile_sales (for consistency), you'll notice that the Painter utility created a mobile_sales.usm file for you. This file must be deployed with your application. The first time your application is run, the UltraLite Java runtime will read in the .usm file and will create the mobile_sales.udb database file to be used by your application. UltraLite Java code also looks a little different than ASA, particularly when setting up the initial connection to the database. UltraLite applications make use of the ianywhere.native_ultralite.DatabaseManager class in order to retrieve a database connection. After the database connection is retrieved, UltraLite supports a much simpler subset of database operations. Contents of individual tables can be retrieved using "find" (that is, findFirst(), findNext(), findBegin(), and so on) or "lookup" (that is, lookupBegin(), lookupForward(), lookupBackward()) methods. Up to four username/password combinations can be stored in the schema in order to provide very simplistic user authentication. As you can see, UltraLite applications will typically be very simple and straightforward database applications, with a few tables and no complicated query or data processing logic.
One other important difference exists between ASA's jConnect libraries and the Native UltraLite for Java libraries. UltraLite's Java classes make use of JNI native methods "beneath the hood" to perform database access. This means that the jul8.jar file must be in your classpath and the uil8.dll file included in your installation's ultralite\NativeUltraLiteForJava\win32 directory must be included in your system path.