これを行う1つの方法は次のとおりです。
PreparedStatement insertStatement= connection.prepareStatement("insert into tablename(col1, col2, col3) values(?,?, select col3 from different_table where name = ?)");
//Then set your parameters accordingly. As per your requirement, the 1st and last paramter should've the same value
もし私があなただったら、私はこれらの線に沿って何かをしたでしょう:
PreparedStatement retrieveStatement= connection.prepareStatement("select col3 from diffferent_table where name=?");
PreparedStatement insertStatement= connection.prepareStatement("insert into tablename(col1, col2, col3) values(?,?, ?)");
//set the value
retrieveStatement.setXX(1,Col1);
retrieveStatement
次に、この値を実行して結果セットから値を取得し、insertStatement
2番目のオプションは、あるテーブルから別のテーブルに値を挿入するときに特定のシナリオを処理する必要がある場合に役立ちます。私はあなたがこれに従ってそしてあなた自身のコードを思い付くことができると思います