1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| public class IdShortener { public static void main(String[] args) { String dbUrl = "jdbc:mysql://"; String dbUser = ""; String dbPassword = "@123"; String sourceTable = "device_instruct"; String targetTable = "new_instruct"; String[] columnsToCopy = {"name", "instruct", "remark", "status"};
try (Connection conn = DriverManager.getConnection(dbUrl, dbUser, dbPassword)) { Statement stmt = conn.createStatement();
String selectQuery = "SELECT name, instruct, remark, status FROM device_instruct"; ResultSet rs = stmt.executeQuery(selectQuery);
while(rs.next()){ String name = rs.getString("name"); String instruct = rs.getString("instruct"); String remark = rs.getString("remark"); String status = rs.getString("status");
}
String sql2 = "insert into new_instruct (name,instruct,remark,status) select name,instruct,remark,status from device_instruct"; stmt.executeUpdate(sql2);
rs.close(); stmt.close();
} catch (SQLException e) { e.printStackTrace(); } } }
|