TestModelUpdate.java 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.Statement;
  4. import java.sql.ResultSet;
  5. public class TestModelUpdate {
  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, 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("当前模型: ID=" + modelId + ", Name=" + modelName);
  21. System.out.println("当前旋转值: X=" + rs.getDouble("rotation_x") + ", Y=" + rs.getDouble("rotation_y") + ", Z=" + rs.getDouble("rotation_z"));
  22. System.out.println("当前缩放值: X=" + rs.getDouble("scale_x") + ", Y=" + rs.getDouble("scale_y") + ", Z=" + rs.getDouble("scale_z"));
  23. // 更新旋转和缩放值
  24. 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;
  25. int rows = stmt.executeUpdate(updateSql);
  26. System.out.println("更新了 " + rows + " 行");
  27. // 再次查询验证
  28. rs = stmt.executeQuery(selectSql);
  29. if (rs.next()) {
  30. System.out.println("更新后旋转值: X=" + rs.getDouble("rotation_x") + ", Y=" + rs.getDouble("rotation_y") + ", Z=" + rs.getDouble("rotation_z"));
  31. System.out.println("更新后缩放值: X=" + rs.getDouble("scale_x") + ", Y=" + rs.getDouble("scale_y") + ", Z=" + rs.getDouble("scale_z"));
  32. }
  33. } else {
  34. System.out.println("没有找到模型记录");
  35. }
  36. rs.close();
  37. stmt.close();
  38. conn.close();
  39. } catch (Exception e) {
  40. e.printStackTrace();
  41. }
  42. }
  43. }