PreparedStatement is not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts

  • kokababu
    replied
    Thank you,

    Now, I am very surprised that not all data is inserted into the table.
    I wanted to insert 5 rows data, only last rows has been inserted into table.

    Leave a comment:


  • JosAH
    replied
    Originally posted by kokababu
    my counter value is 1.
    Move that executeBatch() call out of your loop, i.e. swap lines #15 and #16.

    kind regards,

    Jos

    Leave a comment:


  • kokababu
    replied
    my counter value is 1.

    Leave a comment:


  • JosAH
    replied
    What do you see when you print the 'counter' array obtained in line #15?

    kind regards,

    Jos

    Leave a comment:


  • kokababu
    replied
    Hi,
    Thank you
    I set setAutoComit true and removed commit() from my code.
    But still, no data is inserted into the table. I am very confused.

    Leave a comment:


  • dmjpro
    replied
    Originally posted by kokababu

    My connection is OK and setAutoCommit sets as false.
    You are checking it in another session.
    Whenever you open a connection then a database session opens up, if the setAutoComit(fa lse) is done then the modified data reflected to that session only where you did the operations; otherwise the modified data reflected across all database session. If you check in same session then you must get the modified data.

    Leave a comment:


  • kokababu
    started a topic PreparedStatement is not working

    PreparedStatement is not working

    Hi

    I have to insert multiple rows into a Table. I am inserting rows
    using addBatch and executeBatch.
    Each row has 5 columns. Four columns of each row contain
    same value except last column.
    So I am using for loop to set the last column value.

    I am using JDK1.5, DB2 and WAS6.1. My connection is OK and setAutoCommit sets as false.

    Code:
    String insertStr="INSERT INTO DB.TBLNAME (COL1, COL2, COL3,COL4,COL5) VALUES(?,?,?,?,?)";
    
    PreparedStatement pstmt = con.prepareStatement(insertStr);
    pstmt.setString(1, COL1);	 
    pstmt.setString(2, COL2);
    pstmt.setString(3, COL3);		  					
    pstmt.setString(4, COL4);		  					
    
    int counter[]=null;
    for(int i=0; i<vector.size(); i++){				  
    	pstmt.setString(5, (String)vector.elementAt(i));
            pstmt.addBatch();
    
            counter=pstmt.executeBatch();					
    }
    				  			
     con.commit();
     pstmt.close();
    I am not getting any error message or exception but Nothing is inserted in
    the table. I am not sure why data is not inserted in the table.

    I would be glad if anyone kindly help me to solve this issue.

    Thank you
Working...