简体   繁体   English

如何将行从选择查询动态插入到Java中的另一个表?

[英]How to insert rows dynamically from a select query to another table in java?

I have a select query (using a prepared statement) which returns a Resultset. 我有一个选择查询(使用准备好的语句),它返回一个结果集。 For example the query can be : 例如,查询可以是:

 SELECT * FROM TABLE;

and I want the result of this query to insert in another table, the select query is stored at database and will be usually a join query, so i don't know exactly the columns of the table, how its possible for each row of the Resultset to make an insert row in the form: 而且我想将此查询的结果插入到另一个表中,将选择查询存储在数据库中,并且通常将是一个联接查询,所以我不知道表的确切列,它对于每一行的可能性结果集以以下形式插入行:

INSERT INTO TABLE VALUES ('THE VALUES FROM THE SELECTED ROW IN THE RESULTSET');

you can do both in one state ment: 您可以在一个陈述中同时做这两个事情:

insert into TableB (Col1, col2, col3, col4, etc..)
select Col1, col2, col3, col4, etc.. from Table A where Col5='condition'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM