| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.Statement;
- import java.sql.ResultSet;
- public class TestDatabaseUpdate {
- 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();
-
- // 测试更新模型ID为111的记录
- Long modelId = 111L;
-
- // 先查询当前值
- String selectSql = "SELECT rotation_x, rotation_y, rotation_z, scale_x, scale_y, scale_z FROM WATERSHED_MODEL WHERE model_id = " + modelId;
- ResultSet rs = stmt.executeQuery(selectSql);
-
- if (rs.next()) {
- System.out.println("=== 更新前 ===");
- System.out.println("rotation_x: " + rs.getDouble("rotation_x"));
- System.out.println("rotation_y: " + rs.getDouble("rotation_y"));
- System.out.println("rotation_z: " + rs.getDouble("rotation_z"));
- System.out.println("scale_x: " + rs.getDouble("scale_x"));
- System.out.println("scale_y: " + rs.getDouble("scale_y"));
- System.out.println("scale_z: " + rs.getDouble("scale_z"));
- }
-
- // 执行更新
- String updateSql = "UPDATE WATERSHED_MODEL SET " +
- "rotation_x = 0, rotation_y = 0, rotation_z = 260, " +
- "scale_x = 1, scale_y = 1, scale_z = 1 " +
- "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("rotation_x: " + rs.getDouble("rotation_x"));
- System.out.println("rotation_y: " + rs.getDouble("rotation_y"));
- System.out.println("rotation_z: " + rs.getDouble("rotation_z"));
- System.out.println("scale_x: " + rs.getDouble("scale_x"));
- System.out.println("scale_y: " + rs.getDouble("scale_y"));
- System.out.println("scale_z: " + rs.getDouble("scale_z"));
- }
-
- // 关闭连接
- rs.close();
- stmt.close();
- conn.close();
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
|