| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.Statement;
- import java.sql.ResultSet;
- public class TestModelUpdateWithCoordinates {
- 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, model_coordinates, 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("=== 更新前 ===");
- System.out.println("模型: ID=" + modelId + ", Name=" + modelName);
- System.out.println("坐标: " + rs.getString("model_coordinates"));
- 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 newCoordinates = "116.5,39.9,10.0";
- Double newRotationX = 15.5;
- Double newRotationY = 25.5;
- Double newRotationZ = 35.5;
- Double newScaleX = 1.2;
- Double newScaleY = 1.3;
- Double newScaleZ = 1.4;
-
- // 更新数据(模拟后端 updateWatershedModel 方法)
- String updateSql = "UPDATE WATERSHED_MODEL SET " +
- "model_coordinates = '" + newCoordinates + "', " +
- "rotation_x = " + newRotationX + ", " +
- "rotation_y = " + newRotationY + ", " +
- "rotation_z = " + newRotationZ + ", " +
- "scale_x = " + newScaleX + ", " +
- "scale_y = " + newScaleY + ", " +
- "scale_z = " + newScaleZ + " " +
- "WHERE model_id = " + modelId;
-
- int rows = stmt.executeUpdate(updateSql);
- System.out.println("\n更新了 " + rows + " 行");
-
- // 再次查询验证
- rs = stmt.executeQuery(selectSql);
- if (rs.next()) {
- System.out.println("\n=== 更新后 ===");
- System.out.println("坐标: " + rs.getString("model_coordinates"));
- 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();
- }
- }
- }
|