| | |
| | | |
| | | |
| | | public static void main(String[] args) { |
| | | // 初始数据库配置 |
| | | String initialUrl = "jdbc:mysql://initial_host:3306/initial_db"; |
| | | String username = "user"; |
| | | String password = "pass"; |
| | | |
| | | // 新数据库配置 |
| | | String newUrl = "jdbc:mysql://new_host:3306/new_db"; |
| | | |
| | | // 更改连接URL |
| | | String urlToUse = initialUrl; // 可以根据需要切换到newUrl |
| | | |
| | | // 创建数据库连接属性 |
| | | Properties props = new Properties(); |
| | | props.setProperty("user", username); |
| | | props.setProperty("password", password); |
| | | |
| | | try { |
| | | // 连接到数据库 |
| | | Connection conn = DriverManager.getConnection(urlToUse, props); |
| | | |
| | | // 使用conn进行数据库操作... |
| | | |
| | | // 关闭连接 |
| | | conn.close(); |
| | | } catch (SQLException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | // System.out.println(DateUtil.date()); |
| | | // System.out.println(DateUtil.offsetMonth(DateUtil.date(),-1)); |
| | | } |
| | | |
| | | |