Connecting to Caché
In order to use a Java projection to communicate with the Caché database, you must establish a database connection. There are two types of connections: Regular and Light. Light connections are faster than Regular connections, but support slightly less functionality.
Connection Type | Details |
---|---|
Regular Connection |
|
Light Connection |
|
The following Java client method uses getDatabase to create a regular connection. Notice that getDatabase throws a checked exception of type CacheException. It requires, as an argument, a url specifying the server IP address, the port number of the database, and the name of the Caché Namespace containing the data. The method also requires, as separate arguments, the username and password for the Caché namespace.
public class BindingExamples {
public static Database createConnection() throws CacheException{
String url="jdbc:Cache://localhost:1972/USER";
String username="_SYSTEM";
String pwd="SYS";
Database db = CacheDatabase.getDatabase(url, username, pwd);
return db;
}
}
In general, the connection string for connecting to Caché has the following form: jdbc:Cache://<server>:<port>/<namespace>, where <server> is the IP address of the server hosting Caché, port is the SuperServer port number for your Caché instance, and namespace is the Caché namespace containing your Caché classes and data. Click the About link on the upper left-hand corner of the Management Portal to determine the SuperServer port number for your Caché instance. The default is 1972.