-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathUpdateTransform.java
More file actions
41 lines (30 loc) · 1.14 KB
/
UpdateTransform.java
File metadata and controls
41 lines (30 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package movie;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import oracle.ucp.jdbc.PoolDataSource;
import oracle.ucp.jdbc.PoolDataSourceFactory;
/**
* Performs a partial update using JSON_TRANSFORM.
*
* <p>
* Run first: {@link CreateTable}, {@link Insert}
* </p>
*/
public class UpdateTransform {
public static void main(String[] args) throws SQLException {
PoolDataSource pool = PoolDataSourceFactory.getPoolDataSource();
pool.setURL(String.join("", args));
pool.setConnectionFactoryClassName("oracle.jdbc.pool.OracleDataSource");
try (Connection con = pool.getConnection()) {
PreparedStatement stmt = con.prepareStatement(
"UPDATE movie m " +
"SET m.data = JSON_TRANSFORM(m.data, SET '$.gross' = :1) " +
"WHERE m.data.name.string() = :2");
stmt.setInt(1, 1_000_000_000);
stmt.setString(2, "Iron Man");
stmt.execute();
System.out.println("Movie has been updated!");
}
}
}