Im aware that this question is rampant here in stackoverflow. But all that i've seen so far didnt help me at all. Here is my code:
My public 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 Query:
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);
}
i've read that this is an AUTO_INCREMENT problem. Which make sense since i've set two of my Table Columns to INT. Should i convert String to INT first? Or is there other solutions to this?