docs.intersystems.com
MultiValue Quick Start Tutorial
Connecting a Java Application to Caché
[Home] [Back] [Next]
InterSystems: The power behind what matters   
Search:    

Whether your Java code uses Java projections or JDBC it must create a connection to Caché. In general, there are two different approaches:

  1. Create a com.intersys.objects.CacheDatabase object. When using Java projections you must use this approach. You can also use CacheDatabase with JDBC. Here is an outline of the code for creating the connection:
    String url="jdbc:Cache://<server>:<port>/<Namespace>";
    String username=<UserName>;
    String password=<Password>;
    try {
    Database db = CacheDatabase.getDatabase(url, username, password);
    }
    catch(CacheException ex){ }     
     
  2. Create a java.sql.Connection object. You can use this approach when using standard relational JDBC. Here is an outline of the code for creating the connection:
    String url="jdbc:Cache://<server>:<port>/<Namespace>";
    String username=<UserName>;
    String password=<Password>;
    try{
    Class.forName ("com.intersys.jdbc.CacheDriver");
    Connection dbconnection = DriverManager.getConnection(url,user,password);
    }
    catch (SQLException ex) {
        ex.printStackTrace();
    } 
    catch (ClassNotFoundException ex) {
         ex.printStackTrace();
    }
    
    Note:
    In the above code <Server> refers to the machine hosting Caché. If you are running locally this is localhost. <port> refers to the Caché SuperServer. You can find this number using the Management Portal. At the top of this page click Management Portal–>About. Look under SuperServer Port. In a default Caché installation the port is 1972. If you installed Caché with minimal security, the <UserName> is _system and <Password> is SYS.
    Your Java code can also retrieve connections from com.intersys.jdbc.DataSource objects.


Send us comments on this page
Copyright © 1997-2019 InterSystems Corporation, Cambridge, MA