JDBC Update
The following code executes an SQL UPDATE on a row of the MVFILE.PERSON table. In detail, the code does the following:
-
Creates a connection to Caché using java.sql.Connection.
-
Creates a java.sql.PreparedStatement object and uses it to execute the UPDATE.
-
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();
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.