我有一个返回一百万行的SQL连接查询.
而SQL QUERY是:
SELECT d.*
FROM snomed_conceptdata c, snomed_descriptiondata d
WHERE c.active = 1 and conceptid = c.id AND d.active = 1
Run Code Online (Sandbox Code Playgroud)
我如何检索此数据并将其插入另一个表而不会遇到内存堆空间错误.我目前使用的是Mysql数据库.
我目前的代码:
package Snomed.Snomed;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import catalog.Root;
public class Snomedinfo {
public void snomedinfoinsert()
{
Root oRoot = null;
ResultSet oRsSelect = null;
PreparedStatement oPrStmt = null;
PreparedStatement oPrStmt2 = null;
PreparedStatement oPrStmtSelect = null;
String strSql = null;
ResultSet oRs = null;
String refid = null;
String id = null;
String effectivetime = null;
String active = null;
String moduleid = null;
String conceptid = null;
String languagecode = null;
String typeid = null;
String term = null;
String caseSignificanceid = null;
try{
oRoot = Root.createDbConnection(null);
strSql = "SELECT d.* FROM snomed_conceptdata c, snomed_descriptiondata d WHERE c.active = 1 and conceptid = c.id AND d.active = 1 "; //this query returns a million rows.
oPrStmt2 = oRoot.con.prepareStatement(strSql);
oRs = oPrStmt2.executeQuery();
String sql = "INSERT INTO snomedinfo_date (refid,id,effectivetime,active,moduleid,conceptid,languagecode,typeid,term,caseSignificanceid) VALUES( ?, ?, ?,?,?,?,?,?,?,?)";
oPrStmt = oRoot.con.prepareStatement(sql);
while (oRs.next())
{
refid = Root.TrimString(oRs.getString("refid"));
id = Root.TrimString(oRs.getString("id"));
effectivetime = Root.TrimString(oRs.getString("effectivetime"));
active = Root.TrimString(oRs.getString("active"));
moduleid = Root.TrimString(oRs.getString("moduleid"));
conceptid = Root.TrimString(oRs.getString("conceptid"));
languagecode = Root.TrimString(oRs.getString("languagecode"));
typeid = Root.TrimString(oRs.getString("typeid"));
term = Root.TrimString(oRs.getString("term"));
caseSignificanceid = Root.TrimString(oRs.getString("caseSignificanceid"));
oPrStmt.setString(1, refid);
oPrStmt.setString(2, id);
oPrStmt.setString(3, effectivetime);
oPrStmt.setString(4, active);
oPrStmt.setString(5, moduleid);
oPrStmt.setString(6, conceptid);
oPrStmt.setString(7, languagecode);
oPrStmt.setString(8, typeid );
oPrStmt.setString(9, term);
oPrStmt.setString(10, caseSignificanceid);
oPrStmt.executeUpdate();
}
}
catch (Exception e) {
e.printStackTrace();
}
finally {
oRsSelect = Root.EcwCloseResultSet(oRsSelect);
oRs = Root.EcwCloseResultSet(oRs);
oPrStmt = Root.EcwClosePreparedStatement(oPrStmt);
oPrStmt = Root.EcwClosePreparedStatement(oPrStmt2);
oPrStmt = Root.EcwClosePreparedStatement(oPrStmtSelect);
oRoot = Root.closeDbConnection(null, oRoot);
}
}
public static void main(String args[] ) throws Exception
{
Snomedinfo a = new Snomedinfo();
a .snomedinfoinsert();
}
}
Run Code Online (Sandbox Code Playgroud)
在mysql中,您可以使用create select,或者如果表已经存在insert select
create my_table_copy
SELECT d.*
FROM snomed_conceptdata c
INNER JOIN snomed_descriptiondata d ON c.active = 1
and conceptid = c.id
AND d.active = 1
Run Code Online (Sandbox Code Playgroud)
要么
insert into your_table (col1, col2, col3)
SELECT d.col1, d.col2, d.col3
FROM snomed_conceptdata c
INNER JOIN snomed_descriptiondata d ON c.active = 1
and conceptid = c.id
AND d.active = 1.51
Run Code Online (Sandbox Code Playgroud)
确保你有足够的磁盘空间
| 归档时间: |
|
| 查看次数: |
106 次 |
| 最近记录: |