PreparedStatement is not working
Collapse
X
-
lolz! I expected the answer exactly what you given :)
Actually just i am just testing what happens. But my question is if i do like this then how does it work? I am not clearing batch then each time how it prints counter "one".
Now i tested out this code.
I am getting counter 3 at each print. Then why clearBatch, where it comes in importance?Code:for(int i=0; i<vector.size(); i++){ pstmt.setString(3, (String)vector.elementAt(i)); pstmt.addBatch(); } counter=pstmt.executeBatch(); System.out.println("Counter: " + counter.length); for(int i=0; i<vector.size(); i++){ pstmt.setString(3, (String)vector.elementAt(i)); pstmt.addBatch(); } counter=pstmt.executeBatch(); System.out.println("Counter: " + counter.length);Comment
-
You are just printing the array length; also print the value of each element. The clearBatch() method doesn't do much: it clears the entire batch, that's all; I suspect that a batch will be cleared after an executeBatch() has completed.
kind regards,
JosComment
-
You didn't say anything; you were just obfuscating the entire thing by executing a batch at every loop pass (and ignoring the tip I gave about it in reply #6). You also just printed the length of the counter array which only reflects the number of statements in the batch. Next you added a uniqueness constraint on your table and were flabbergasted that nothing (non-unique) was added to your table.
Please read the replies from the 'experts' before you start to experiment in the wild.
kind regards,
JosComment
Comment