java - Is it possible to insert into multiple tables on Oracle using PreparedStatement? -
i tried code insert oracle multiple tables. doesn't execute. can me?
here code:
string sql = "insert all" + "into t_stock_purchase values(?,?,?,?)" + "into t_stocks values(?,?,?)" + "into t_stock_status(godownname,itemname,receivedfrom,receiveddate,receivedqty,availablebal) values(?,?,?,?,?,?)" + "select 1 dual"; ps = con.preparestatement(sql); int rowcount = purchasetable.getrowcount(); system.out.println("row count = "+rowcount); (int = 0; < rowcount; i++) { ps.setstring(1, partynamelable); ps.setstring(2, datelable); ps.setstring(3, (string) purchasetable.getvalueat(i, 0)); ps.setint(4, (int) purchasetable.getvalueat(i, 1)); ps.setstring(5, "purchase"); ps.setstring(6, (string) purchasetable.getvalueat(i, 0)); ps.setint(7, (int) purchasetable.getvalueat(i, 1)); ps.setstring(8, "purchase"); ps.setstring(9, (string) purchasetable.getvalueat(i, 0)); ps.setstring(10, partynamelable); ps.setstring(11, datelable); ps.setint(12, (int) purchasetable.getvalueat(i, 1)); ps.setint(13, (int) purchasetable.getvalueat(i, 1)); ps.execute(); } is right way?, if there possibles please provide me.
thanks in advance.
you're building sql statement concatenating strings, aren't leaving spaces between clauses; end insert allinto t_stoc... isn't valid. have duplicated into in second clause.
you said aren't getting errors, may suppressing them later in code. should investigate why aren't seeing exception statement not valid.
add space @ start of each added string, @ least necessary syntax valid:
string sql = "insert all" + " t_stock_purchase values(?,?,?,?)" + " t_stocks values(?,?,?)" + " t_stock_status(godownname,itemname,receivedfrom," + "receiveddate,receivedqty,availablebal) values(?,?,?,?,?,?)" + " select 1 dual"; ... or @ end of each string if prefer.
it's better practice specify column names of inserts, if inserting values every column - it's clearer, , makes easier spot mistakes in ordering.
Comments
Post a Comment