Skip to main content

Connecting Using CacheDatabase

You can also use com.intersys.objects.CacheDatabase to create a connnection. Its getDatabase method returns a com.intersys.objects.Database object. This class parallels java.sql.Connection. Its createStatement method returns a java.sql.Statement object which can then be used to query and update the database. Database also contains methods for managing transactions.

The following method creates and returns a Database object:


public class JDBCExamples {
   public static Database getDatabase() throws CacheException{
      String url="jdbc:Cache://localhost:1972/USER";
      String username="_SYSTEM";
      String pwd="SYS";
      Database db =
         CacheDatabase.getDatabase(url, username, pwd);
      return db;
   }
}

Notice that the database url passed to getDatabase is identical to the url passed to DriverManager using the standard JDBC approach for connecting to Caché.

Note:

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.

To learn more about CacheDatabase and Database, read the API documentation stored in <cachesys>\dev\java\doc. In a standard Windows installation <cachesys> is C:\InterSystems\Cache. In a standard UNIX® or Linux installation it is /usr/cachesys.

FeedbackOpens in a new tab