Skip to main content

This is documentation for Caché & Ensemble. See the InterSystems IRIS version of this content.

For information on migrating to InterSystems IRIS, see Why Migrate to InterSystems IRIS?

JDBC Update

The following code executes an SQL UPDATE on a row of the MVFILE.PERSON table. In detail, the code does the following:

  1. Creates a connection to Caché using java.sql.Connection.

  2. Creates a java.sql.PreparedStatement object and uses it to execute the UPDATE.

  3. Closes the database connection.


//Create the connection
Class.forName("com.intersys.jdbc.CacheDriver");
String url="jdbc:Cache://localhost:1972/MyAccount";
Connection conn = DriverManager.getConnection(url);
           
//created the prepared statement  
String sql = "UPDATE MVFILE.PERSON (AGE,PHONE) VALUES" +
            " ('45','111-111-1111,222-222-2222') WHERE NAME='IDLE,JIM'";
PreparedStatement pstmt = conn.prepareStatement(sql);
        
//execute the update
int status = pstmt.executeUpdate();
System.out.printf("Status %s",status);
           
 conn.close();       
Note:

The above code is contained in RunUpdate.java. This file is in <cachesys>\Dev\tutorials\mv. Executing the Java Examples contains step-by-step instructions for executing this code.

Feedback