Error picking up Time type data from database

Asked

Viewed 173 times

1

I am making a query but it is giving error when I try to get values of type Time. This is the error:

java.sql.Sqlexception: java.sql.Sqlexception: Bad format for Time '13:00:00.000' in column 5

The line that’s firing the exception is this:

linha.setHoraInicial(resultado.getTime("hora_inicio"));

Save the time in the bank in such a way:

 DateFormat dateFormat = new SimpleDateFormat("hh:mm");
            java.sql.Time timeValue = new java.sql.Time(dateFormat.parse(txtHoraInicial.getText()).getTime());
            System.out.println("Time: " + timeValue);
            c.setHoraInicial(timeValue);

And I do it in the saving method that stays on the DAO:

comando.setTime(4, a.getHoraInicial());

And this is the StackTrace complete:

java.sql.Sqlexception: java.sql.Sqlexception: Bad format for Time '13:00:00.000' in column 5 at com.mysql.jdbc.SQLError.createSQLException(Sqlerror.java:910) at com.mysql.jdbc.ResultSet.getTimeFromBytes(Resultset.java:6164) at com.mysql.jdbc.ResultSet.getTimeInternal(Resultset.java:6198) at com.mysql.jdbc.ResultSet.getTime(Resultset.java:5779) at com.mysql.jdbc.ResultSet.getTime(Resultset.java:5814) at com.agenda.dao.AgendaDAO.buscar(Scheduled.java:84) at com.agenda.view.FrmAgendaController.updateName(Frmagendacontroller.java:138) at com.agenda.view.FrmAgendaController.init(Frmagendacontroller.java:127) at com.agenda.view.FrmAgendaController.initialize(Frmagendacontroller.java:83) at javafx.fxml.Fxmlloader.loadImpl(Fxmlloader.java:2552) at javafx.fxml.Fxmlloader.loadImpl(Fxmlloader.java:2445) at javafx.fxml.Fxmlloader.loadImpl(Fxmlloader.java:3218) at javafx.fxml.Fxmlloader.loadImpl(Fxmlloader.java:3179) at javafx.fxml.Fxmlloader.loadImpl(Fxmlloader.java:3152) at javafx.fxml.Fxmlloader.loadImpl(Fxmlloader.java:3128) at javafx.fxml.Fxmlloader.loadImpl(Fxmlloader.java:3108) at javafx.fxml.Fxmlloader.load(Fxmlloader.java:3101) at com.agenda.view.Agenda.start(Agenda.java:22) at com.sun.javafx.application.Launcherimpl.lambda$launchApplication1$159(Launcherimpl.java:863) at com.sun.javafx.application.Launcherimpl$$Lambda$53/681110827.run(Unknown Source) at com.sun.javafx.application.Platformimpl.lambda$runAndWait$172(Platformimpl.java:326) at com.sun.javafx.application.Platformimpl$$Lambda$46/355629945.run(Unknown Source) at com.sun.javafx.application.Platformimpl.lambda$null$170(Platformimpl.java:295) at com.sun.javafx.application.Platformimpl$$Lambda$48/1296242029.run(Unknown Source) at java.security.Accesscontroller.doPrivileged(Native Method) at com.sun.javafx.application.Platformimpl.lambda$runLater$171(Platformimpl.java:294) at com.sun.javafx.application.Platformimpl$$Lambda$47/1915503092.run(Unknown Source) at com.sun.Glass.ui.Invokelaterdispatcher$Future.run(Invokelaterdispatcher.java:95) at com.sun.Glass.ui.win.WinApplication. _runLoop(Native Method) at com.sun.Glass.ui.win.WinApplication.lambda$null$145(Winapplication.java:101) at com.sun.Glass.ui.win.Winapplication$$Lambda$36/1963387170.run(Unknown Source) at java.lang.Thread.run(Thread.java:745)

  • What type of object "result"?

  • My dear, what is the type of this 'Opening' field? Would it be a Date or a String? If you could put more details, it would help.

  • The guy is java.sql.Time

  • I can include the figures perfectly in the bank, but when it comes to checking the error

  • Correct me if I’m wrong, but the method getTime() does not accept any kind of argument. See: http://docs.oracle.com/javase/7/docs/api/java/util/Date.html#getTime() You did not want to use setTime()?

  • @Math the getTime which he refers to is probably that of ResultSet, since it is recovering data from a database

  • That, I’m trying to recover the data.

  • @Techies what kind of data in the database? I ran a simple test here and it worked, so consider including more information, with stack trace complete and how you save the data (as arrow the parameter in statement), if possible show how the date is persisted in the database

  • I’m using Mysql, I’m not saving the date just by the hour. I include a snippet of how I Seto the Time so that it can be saved in the bank. I’ll add the stack trace to the question

  • I edited the question put how I save the time and the full Stacktrace

  • @Techies is expensive, simple way here worked, so I can’t help you =/ Anyway thanks

  • Wouldn’t it be because you’re using the time 13 when in fact your bank expects 1 p.m.?

  • I don’t know, because I’m saving time at the bank.

  • Look at the database: http://i.stack.Imgur.com/V7tct.png

  • I ran some tests and changed everything to Int except for the type Time field in the database. When I change to Int I can recover but only the time comes, for example if I have 13:50:00.000 only comes the 13 I wish the seconds would come too.

  • Can’t you change and work with timestamp? when you were recovering just use a Format on your team and work as you wish... @Techies

  • I haven’t tried with Timestamp yet, I have to change the database and model variables that get hours to Timestamp?

Show 12 more comments

1 answer

0


Problem Solved, in the database I changed the Default from the time to 00:00:00 in that way: inserir a descrição da imagem aqui

After I did that it worked, before date format like that: 13:00:00.000

Browser other questions tagged

You are not signed in. Login or sign up in order to post.