我需要使用java和HSQLDB
将数据从MYSQL
文本表复制到INSERT into...as SELECT...
。不知道怎么离开这里。
...
Connection hcon = DriverManager.getConnection(param1); #hsql connection
...
Connection mscon = DriverManager.getConnection(param2); #mysql connection
...
Statement htmt = hcon.createStatement();
Statement mstmt = mscon.createStatement();
...
#How do I reference MySQL here?
ResultSet r = hstmt.executeQuery("insert into mysqlemp as select * from hsqlemp");
我知道有一个LOAD DATA INFILE...
可以将文本加载到表格中,而不是我的选项。
答案 0 :(得分:1)
你的做法是错误的。您无法使用与HSQL数据库建立的连接访问MySQL数据库。你可以这样做:
PreparedStatement loadStatement = hcon.prepareStatement("SELECT data FROM table");
PreparedStatement storeStatement = mscon.prepareStatement("INSERT INTO table (data) VALUES (?)");
ResultSet loadedData = loadStatement.executeQuery();
while (loadedData.next()) {
storeStatement.setString(1, loadedData.getString(1));
storeStatement.executeUpdate();
}