| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.Statement;
- import java.sql.ResultSet;
- public class TestModelUpdate {
- public static void main(String[] args) {
- try {
- Class.forName("dm.jdbc.driver.DmDriver");
-
- String url = "jdbc:dm://192.168.0.145:30236?charSet=utf8";
- String username = "WATERSHED";
- String password = "WaterShed./1224";
-
- Connection conn = DriverManager.getConnection(url, username, password);
- Statement stmt = conn.createStatement();
-
- // 查询第一条记录
- String selectSql = "SELECT model_id, model_name, rotation_x, rotation_y, rotation_z, scale_x, scale_y, scale_z FROM WATERSHED_MODEL WHERE ROWNUM <= 1";
- ResultSet rs = stmt.executeQuery(selectSql);
-
- if (rs.next()) {
- Long modelId = rs.getLong("model_id");
- String modelName = rs.getString("model_name");
-
- System.out.println("当前模型: ID=" + modelId + ", Name=" + modelName);
- System.out.println("当前旋转值: X=" + rs.getDouble("rotation_x") + ", Y=" + rs.getDouble("rotation_y") + ", Z=" + rs.getDouble("rotation_z"));
- System.out.println("当前缩放值: X=" + rs.getDouble("scale_x") + ", Y=" + rs.getDouble("scale_y") + ", Z=" + rs.getDouble("scale_z"));
-
- // 更新旋转和缩放值
- String updateSql = "UPDATE WATERSHED_MODEL SET rotation_x = 10.5, rotation_y = 20.5, rotation_z = 30.5, scale_x = 1.5, scale_y = 2.5, scale_z = 3.5 WHERE model_id = " + modelId;
- int rows = stmt.executeUpdate(updateSql);
-
- System.out.println("更新了 " + rows + " 行");
-
- // 再次查询验证
- rs = stmt.executeQuery(selectSql);
- if (rs.next()) {
- System.out.println("更新后旋转值: X=" + rs.getDouble("rotation_x") + ", Y=" + rs.getDouble("rotation_y") + ", Z=" + rs.getDouble("rotation_z"));
- System.out.println("更新后缩放值: X=" + rs.getDouble("scale_x") + ", Y=" + rs.getDouble("scale_y") + ", Z=" + rs.getDouble("scale_z"));
- }
- } else {
- System.out.println("没有找到模型记录");
- }
-
- rs.close();
- stmt.close();
- conn.close();
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
|