本文介绍了如何在不使用INSERT INTO SELECT语句的情况下将该程序实现为导入表中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

目前,导入/插入过程完美无缺。但是我不想为插入和选择编写单个查询,而是编写一个单独的查询来从'snomed_descriptiondata'表中选择,并单独查询以插入'snomedinfo'_data表。

Currently the import/insert process is working perfectly. But I don't want to write a single query for both inserting and selecting but rather write a separate query for selecting from 'snomed_descriptiondata' table and separate query for inserting to 'snomedinfo'_data table.

我当前的代码:

package Snomed.Snomed;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Date;

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;
    String strSql2 = null;
    String snomedcode=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;
    int count = 0;
    final int batchSize = 1000;
    try{
    oRoot = Root.createDbConnection(null);
    strSql = "SELECT  id FROM snomed_conceptdata WHERE active=1 ";
    oPrStmt2 = oRoot.con.prepareStatement(strSql);
    oRsSelect = oPrStmt2.executeQuery();
    String sql = "INSERT INTO snomedinfo_data (refid,id,effectivetime,active,moduleid,conceptid,languagecode,typeid,term,caseSignificanceid)SELECT refid,id,effectivetime,active,moduleid,conceptid,languagecode,typeid,term,caseSignificanceid from snomed_descriptiondata WHERE conceptid =? AND active=1" ;
    oPrStmtSelect = oRoot.con.prepareStatement(sql);
    while (oRsSelect.next()) {
        snomedcode = Root.TrimString(oRsSelect.getString("id"));
        //String sql = "INSERT INTO snomedinfo_data (refid,id,effectivetime,active,moduleid,conceptid,languagecode,typeid,term,caseSignificanceid)SELECT refid,id,effectivetime,active,moduleid,conceptid,languagecode,typeid,term,caseSignificanceid from snomed_descriptiondata WHERE conceptid =? AND active=1" ;
        //oPrStmtSelect = oRoot.con.prepareStatement(sql);
        oPrStmtSelect.setString(1,snomedcode);

        oPrStmtSelect.executeUpdate();
        }

    //oPrStmtSelect.executeBatch();
    System.out.println("done");
    }

    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();
      }
}

注意:如何在不使用嵌套的情况下执行此操作循环?有人能为我提供符合我的程序的解决方案吗?

Note: how do I do this without using nested while loops? Can someone provide me a solution that is in accordance with my program?

推荐答案

你可以(并且应该)包含概念标识 - 在 IN 子句中选择查询:

You can (and should) include the concept-id-selecting query within an IN clause:

INSERT INTO snomedinfo_data (refid, id, effectivetime, active, moduleid, conceptid,
                             languagecode, typeid, term, caseSignificanceid)
    SELECT refid, id, effectivetime, active, moduleid, conceptid,
                    languagecode, typeid, term, caseSignificanceid
           FROM snomed_descriptiondata
           WHERE active = 1 AND conceptid IN
               (SELECT cd.id FROM snomed_conceptdata cd WHERE cd.active = 1)

这种方式你应该能够在一个语句中做所有事情,比逐行处理相同数据要快几个数量级(又名慢速) -slow)由JDBC驱动程序。

This way you should be able to do everything in one statement which will be orders of magnitude faster than processing the same data row-by-row (a.k.a slow-by-slow) by the JDBC driver.

这篇关于如何在不使用INSERT INTO SELECT语句的情况下将该程序实现为导入表中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 12:59