JSpinner Value into Database?
-
How would I get the JSpinner value into database?, the value is in alphanumeric Like 1month 2month
String[] monthStrings = {"1Month","3Month","6Month","1Year"};
SpinnerListModel monthModel = new SpinnerListModel(monthStrings);
JSpinner spinner = new JSpinner(monthModel); -
How would I get the JSpinner value into database?, the value is in alphanumeric Like 1month 2month
String[] monthStrings = {"1Month","3Month","6Month","1Year"};
SpinnerListModel monthModel = new SpinnerListModel(monthStrings);
JSpinner spinner = new JSpinner(monthModel);chdboy wrote:
How would I get the JSpinner value into database?
The same way you would put any value into the database; what exactly is the difficulty? Given also that it is just a short list, maybe storing the index value rather than the string would be the best idea.
Veni, vidi, abiit domum
-
chdboy wrote:
How would I get the JSpinner value into database?
The same way you would put any value into the database; what exactly is the difficulty? Given also that it is just a short list, maybe storing the index value rather than the string would be the best idea.
Veni, vidi, abiit domum
Here is the code ,how I'm saving the JSpinner value
statement.setString(27,JSpinner.getValue());
Under setString red line and the error is
The method setString(int, String) in the type PreparedStatement is not applicable for the arguments (int, Object)
and Under
JSpinner.getValue()
red line and error says
Cannot make a static reference to the non-static method getValue() from the type JSpinner
-
Here is the code ,how I'm saving the JSpinner value
statement.setString(27,JSpinner.getValue());
Under setString red line and the error is
The method setString(int, String) in the type PreparedStatement is not applicable for the arguments (int, Object)
and Under
JSpinner.getValue()
red line and error says
Cannot make a static reference to the non-static method getValue() from the type JSpinner
-
You cannot use
JSpinner.getValue()
, you need to callgetValue()
on an instance of theJSpinner
class.Veni, vidi, abiit domum
I tried
statement.setString(27,(String)spinner.getValue());
and I get
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
EDIT: It worked with
statement.setString(27,(String)spinner.getValue().toString());
-
I tried
statement.setString(27,(String)spinner.getValue());
and I get
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
EDIT: It worked with
statement.setString(27,(String)spinner.getValue().toString());
You should go back to your Java documentation or tutorials and learn why and when it is possible to use casts. Simply stated, you cannot use a cast to convert one object type to another. You also need to decide in advance what object type you want to store in the database, and write the code to handle that specific situation.
Veni, vidi, abiit domum