package a;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
public class Main {
private static Connection c = null;
private static PreparedStatement ps = null;
private static PreparedStatement ps2 = null;
private static ResultSet rs = null;
public static void main(String[] args) {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
c = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydata?characterEncoding=gbk", "root", "");
ps = c.prepareStatement("select * from t_user");
rs = ps.executeQuery();
while (rs.next()) {
ps2 = c.prepareStatement("insert into t_user_Memory values (null, ?, ?)");
ps2.setString(1, rs.getString(2));
ps2.setString(2, rs.getString(3));
ps2.executeUpdate();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (rs != null) {
rs.close();
rs = null;
}
if (ps2 != null) {
ps2.close();
ps2 = null;
}
if (ps != null) {
ps.close();
ps = null;
}
if (c != null) {
c.close();
c = null;
}
} catch (Exception e) {
// TODO: handle exception
}
}
}
}