Question

I have some pre defined time in mysql database in varchar format for example - 16:45, 00:30, 09:15, 20:50 and 10 more.

I want to display any one of these time in jspinner I am trying but getting error this my jspinner setup where I am displaying the time this is inside constructor-

Date date = new Date();
SpinnerDateModel sm = new SpinnerDateModel(date, null, null, Calendar.HOUR_OF_DAY);
arr_time.setModel(sm);
JSpinner.DateEditor ar = new JSpinner.DateEditor(arr_time, "HH:mm");
arr_time.setEditor(ar);

and this my modify button code where I fetching the time as string from database trying to show them in jspinner

try {
    if (evt.getActionCommand().equals("Modify")) {
        String flno=JOptionPane.showInputDialog(this, "Enter Flight Number");
        String sql="SELECT * FROM flights WHERE flightno='"+flno+"'";
        smt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
        rs = smt.executeQuery(sql);
        while (rs.next()) {
            jTextField1.setText(rs.getString(1));
            arr_time.setValue(rs.getString(2));
            jTextField4.setText(rs.getString(4));
            jTextField5.setText(rs.getString(5));
        }
    } else if(evt.getActionCommand().equals("Update")) {
    }

run: illegal value

Error is coming in netbeans 7.1

Was it helpful?

Solution

Although not obvious, the error is telling you the type used to set the JSpinner and the String read in from the database are incompatible. SpinnerDateModel uses a Date as the underlying object type

Try

SimpleDateFormat format = new SimpleDateFormat("HH:mm");
arr_time.setValue(format.parseObject(rs.getString(2))); // e.g. input 16:45
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top