java - Is it a good practice to use foreach for multiple insertions on a database? -


i have message , many recipients, want know when want save it.. use statement.execute() each recipient message have or considered "hard-coding"

   public void save(int id,string subject, string body, arraylist<string> emails){      string sq = "call savemessage(?,?)";     callablestatement st = this.connection.preparecall(sq);     st.setint(1,id);     st.setstring(2, subject);     st.setstring(3, body);     st.execute();      for(string e:emails){         query = "call saverecipientbymessage(?,?)";        callablestatement st2 = this.connection.preparecall(query);        st2.setint(1,id);        st2.setstring(2,e);        st2.execute();     } } 

thanks reading.

the foreach ok better jdbc practice here use batch.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -