Question: Im having troubles converting my String to integer. My Data Table consist of 3 columns, two of which are INT type. But when i started inserting my String to my Database it gives an Auto\_Increment error:

Class:

```
public class Strong extends javax.swing.JFrame {

  String a;

    public Apply() {
        initComponents();
         jTable1.getSelectionModel().addListSelectionListener(new ListSelectionListener()
        {
            @Override
            public void valueChanged(ListSelectionEvent e)
            {
                int selectedRow = jTable1.getSelectedRow();
                a = (String) jTable1.getValueAt(selectedRow, 0);

            }
        }
        );

    }

```

My executeUpdate:

```
try{

           Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/application","root","");
            String sql= "insert into Mycart values(?,?,?)";
            PreparedStatement pst = con.prepareStatement(sql);            
            pst.setString(1, (String)a);
            pst.setString(2, (String)a);
            pst.setString(3, (String)a);

            pst.executeUpdate();
            JOptionPane.showMessageDialog(null, "Added to Cart");

        }
        catch(Exception e){
            JOptionPane.showMessageDialog(null, e);
        }

```

This is actually a follow up regarding my previous question. My Question is that how can i convert my String to Integer and then insert it on my Database? If you might ask i got my String from my jTable which then got it from my database. What i want to do now is that get the values inside that jTable and insert it to a new Database.

Answer: 
Use [`event.stopImmediatePropagation()`](https://api.jquery.com/event.stopimmediatepropagation/) in the button click handler to stop event from bubbling.

```
$(".addtocart").click(function (event) {
    //                          ^^^^^    Pass event object to the callback
    //add to cart

    event.stopImmediatePropagation();
});

```

---

**EDIT:**

If both the handlers are same, I'll suggest to use only a delegated handler for both dynamic and static elements.

```
$(document).on('click', 'button.btn.btn-primary.addtocart', function () {
    // add to cart
});

```
It is a easy solution.

Just use on method in jQuery.

```
$(document).ready(function(){
    $("dynamically_created_element_selector").on("click", function()
    {
        //do whatever u want
    });
});

```

Demo is here-
-------------

```js
$(function(){
    $('button').on('click',function(){
        var r= $('<br/><button class="dynamic_button" type="button">Dynamic Button</button>');
        $("body").append(r);
    });

    $(document).on('click', 'button.dynamic_button', function ()
    {
        alert("Dynamic Element Clicked !!");
    });

});
```

```html
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

<body>
    <button>Insert after</button> 
</body>
```