![]() |
Cloudscape Basics and the Sample Database
|
|
Working with ConnectionsOnce an application has loaded the Cloudscape JDBC driver, the application can connect to an existing database or create a new database. All of the application's interactions are then handled through the JDBC API, the classes and methods of java.sql. Applications connect to databases (and create them, if they do not exist) with the java.sql.DriverManager.getConnection method. Applications specify a database connection URL as a String parameter to this method. Calling this method with the appropriate URL string returns a connection to a database. Cloudscape's database connection URL consists of four parts, as shown in Figure 2-4. Figure 2-4 Syntax of the Cloudscape database connection URL The first two never change; the third part (which is optional) indicates the name of the database you want to connect to. The fourth part consists of zero or more attributes. An attribute is how we will specify that we want to create a new database (instead of connecting to an existing one). In this section, we will create a database called HelloWorldDB. Creating this database requires a database connection URL as shown in Figure 2-5. Figure 2-5 This Cloudscape database connection URL creates a new database called HelloWorldDB. Get a Connection: Create a DatabaseIn this project, you will run a Java program that creates a new database.
Figure 2-6 This Cloudscape database connection URL creates a new database called HelloWorldDB.
Shut Down CloudscapeAs you saw, starting up Cloudscape was a separate step from getting a connection to a database. Shutting down Cloudscape is likewise a separate step. It is important to shut down Cloudscape when the application is through interacting with embedded Cloudscape, because the shutdown command ensures that all changes are written from the database log (a temporary holding place for transactions) to the actual database. If you do not shut down Cloudscape, the next time it starts up, it takes the time to run recovery on the databases in the system. Recovery means restoring a database to its last committed state after a system failure (or stopping the application without a shutdown command) based on information stored in a special area called the database log. In this task, you will delete HelloWorldDB, edit the CreateWorldDB program to include disconnect and shutdown commands, and rerun the program.
Examine the System Directory and Information LogYour application has now created and interacted with a Cloudscape database. Examine the contents of your system directory. The directory should now include:
|
||
|
![]() Cloudscape Version 3.6 For information about Cloudscape technical support, go to: www.cloudscape.com/support/.Copyright © 1998, 1999, 2000 Informix Software, Inc. All rights reserved. |