I'm trying to DELETE some data from SQL when a button is clicked. However, I keep getting the error java.lang.NumberFormatException: null when the button is clicked. This confusses me because I can display the ID in my jsp.file, so i know the value is selected and displayed.
Here is my jsp file:
if (request.getParameter("delete") != null){
long betID = Long.parseLong(request.getParameter("id"));
System.out.print(betID);
}
<form action="newBet.jsp" method="get">
<fieldset>
<input class="btn btn-default" type="submit" name="w" value="Vundet"/>
<input class="btn btn-default" type="submit" name="L" value="Tabt" />
<input type="submit" name="id" value="<%=bet.getId()%>"/>
</fieldset>
</form>
This successfully shows the value bet.getId() in my jsp file. I will ofc change type to "hidden" when I'm done. The problem is when I click the button "delete" it does not ready my value.
Here is my Java:
public static void removeBet(long betID) throws SQLException {
Connection connection = null;
try {
DB_Connection connect = new DB_Connection();
connection=connect.get_Connection();
String sql = "DELETE FROM bets WHERE id = ?";
PreparedStatement ps = connection.prepareStatement(sql);
ps.setLong(1, betID);
ps.executeUpdate();
}catch (SQLException e) {
e.printStackTrace();
} finally {
connection.close();
}
The value of my betID is set to long everywhere in my code. I hope some of you might be able to help me. I've checked similar questions, but unfortunatly I've not been able to solve the issues. Thank you.