Copy One Database Table to Another
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
public class Main {
public static void main(String[] argv) throws Exception {
String url = "jdbc:mysql://localhost:3306/";
String dbName = "jdbcMysql";
String userName = "root";
String password = "root";
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection(url + dbName, userName, password);
Statement st = conn.createStatement();
int rows = st.executeUpdate("INSERT INTO myTable SELECT * FROM jdbc4.Copyemployee");
if (rows == 0) {
System.out.println("Don't add any row!");
} else {
System.out.println(rows + " row(s)affected.");
conn.close();
}
}
}
Related examples in the same category