converting string to integer for prepared statment
Iam using javafx to update the database using prepardstatement but while running it iam getting this error at the console and doesnt shows while compilation. It looks like the string is not getting the values whatever entered in it. maybe i was wrong still figuring out
var input: TextBox;
var inputnum = Integer.parseInt({input.text});
stmt = conn.prepareStatement("INSERT into dummy2 values(?,?,?)");
stmt.setString(1,"");
stmt.setString(2, "");
stmt.setInt(3, inputnum);
Getting error:-
java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:468)
at java.lang.Integer.parseInt(Integer.java:497)
at testint.Main$Main$Script.applyDefaults$(Main.fx开发者_StackOverflow:36)
at testint.Main$Main$Script.applyDefaults$(Main.fx:36)
at testint.Main.javafx$run$(Main.fx)
Because string you are trying to parse is ""
which isn't parsable to int
.
You probably need to validate the input or if you want to allow ""
then assign some default value for such case.
It wouldn't show at compile-time, no - input.text
is an empty string (at execution time), and when you try to parse it, that's failing.
You need to work out what you want to do when input.text
is empty.
精彩评论