[英]select from one table to another table in jdbc
How to execute SQL Server query into JDBC like this SQL?如何像这样 SQL 那样在 JDBC 中执行 SQL Server 查询?
select * into bk_table from existing_table
Expected : Above query should be executed through JDBC.预期:上述查询应通过 JDBC 执行。
Actual : Query is not working through JDBC in any way.I tried following two ways but nothing happens or affected in DBMS.实际:查询无法通过 JDBC 以任何方式工作。我尝试了以下两种方式,但在 DBMS 中没有任何反应或影响。
String sql="select * into bk_table from existing_table";
//tried way 1-> result: false
statement.execute(sql);
//tried way 2-> result: -1
statement.executeUpdate(sql);
What to do now?现在做什么?
You need to use an insert-select statement.您需要使用插入-选择语句。 It can be called with
executeUpdate
:可以使用
executeUpdate
:
String sql = "INSERT INTO bk_table SELECT * FROM existing_table";
statement.executeUpdate(sql);
To select data from old table, "SELECT * FROM bk_table";从旧表中选择数据,"SELECT * FROM bk_table";
To insert the selected data from old to existing table, "INSERT INTO existing_table SELECT * FROM bk_table";要将旧表中的选定数据插入到现有表中,“INSERT INTO existing_table SELECT * FROM bk_table”;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.