TestModelUpdateWithCoordinates.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.Statement;
  4. import java.sql.ResultSet;
  5. public class TestModelUpdateWithCoordinates {
  6. public static void main(String[] args) {
  7. try {
  8. Class.forName("dm.jdbc.driver.DmDriver");
  9. String url = "jdbc:dm://192.168.0.145:30236?charSet=utf8";
  10. String username = "WATERSHED";
  11. String password = "WaterShed./1224";
  12. Connection conn = DriverManager.getConnection(url, username, password);
  13. Statement stmt = conn.createStatement();
  14. // 查询第一个模型
  15. 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";
  16. ResultSet rs = stmt.executeQuery(selectSql);
  17. if (rs.next()) {
  18. Long modelId = rs.getLong("model_id");
  19. String modelName = rs.getString("model_name");
  20. System.out.println("=== 更新前 ===");
  21. System.out.println("模型: ID=" + modelId + ", Name=" + modelName);
  22. System.out.println("坐标: " + rs.getString("model_coordinates"));
  23. System.out.println("旋转: X=" + rs.getDouble("rotation_x") + ", Y=" + rs.getDouble("rotation_y") + ", Z=" + rs.getDouble("rotation_z"));
  24. System.out.println("缩放: X=" + rs.getDouble("scale_x") + ", Y=" + rs.getDouble("scale_y") + ", Z=" + rs.getDouble("scale_z"));
  25. // 模拟前端发送的更新数据
  26. String newCoordinates = "116.5,39.9,10.0";
  27. Double newRotationX = 15.5;
  28. Double newRotationY = 25.5;
  29. Double newRotationZ = 35.5;
  30. Double newScaleX = 1.2;
  31. Double newScaleY = 1.3;
  32. Double newScaleZ = 1.4;
  33. // 更新数据(模拟后端 updateWatershedModel 方法)
  34. String updateSql = "UPDATE WATERSHED_MODEL SET " +
  35. "model_coordinates = '" + newCoordinates + "', " +
  36. "rotation_x = " + newRotationX + ", " +
  37. "rotation_y = " + newRotationY + ", " +
  38. "rotation_z = " + newRotationZ + ", " +
  39. "scale_x = " + newScaleX + ", " +
  40. "scale_y = " + newScaleY + ", " +
  41. "scale_z = " + newScaleZ + " " +
  42. "WHERE model_id = " + modelId;
  43. int rows = stmt.executeUpdate(updateSql);
  44. System.out.println("\n更新了 " + rows + " 行");
  45. // 再次查询验证
  46. rs = stmt.executeQuery(selectSql);
  47. if (rs.next()) {
  48. System.out.println("\n=== 更新后 ===");
  49. System.out.println("坐标: " + rs.getString("model_coordinates"));
  50. System.out.println("旋转: X=" + rs.getDouble("rotation_x") + ", Y=" + rs.getDouble("rotation_y") + ", Z=" + rs.getDouble("rotation_z"));
  51. System.out.println("缩放: X=" + rs.getDouble("scale_x") + ", Y=" + rs.getDouble("scale_y") + ", Z=" + rs.getDouble("scale_z"));
  52. }
  53. } else {
  54. System.out.println("没有找到模型记录");
  55. }
  56. rs.close();
  57. stmt.close();
  58. conn.close();
  59. } catch (Exception e) {
  60. e.printStackTrace();
  61. }
  62. }
  63. }