I have db named spareparts in which all values are stored as varchar(20). I am taking input from the user through jtextfield as a number then convert into integer. s1(which is itemcode) and s2(which is quantity to be added to actual quantity) are the input Now I want to add this input into 'quantity'(which is also varchar) as:
public class AddStockDAO{
Connection connection;
PreparedStatement preparedStatement;
ResultSet resultSet;
Statement statement;
public AddStockDAO(String s1,String s2)
{
int num=Integer.parseInt(s2);
String sql= "select "+
" cast(quantity as INT) from spareparts"+
"set quantity+= "+num+
" cast(quantity as varchar(20))"+
"where itemcode='?'";
try (Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb", "root", "")) {
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, s1);
stmt.executeUpdate();
}
} catch (SQLException ex) {
Logger.getLogger(AddProductGUI.class.getName()).log(Level.SEVERE, null, ex);
}
}
}