TP04 datetime trouble

Modérateurs : graffion, jmdouin, agoncal, mlebihan

renjunzhou
Messages : 5
Inscription : 06 nov. 2016 17:50

TP04 datetime trouble

Message par renjunzhou » 06 nov. 2016 17:57

SQL message : Data truncation: Incorrect datetime value: '{SysUpTime = 171116 days 14:5:34} {Timestamp = Sun Nov 06 16:48:33 CET 2016}' for column 'orderdate' at row 1

the older same question in there can't resolve this trouble, and i google it weather because the new edition of mysql change it DATA format

Code : Tout sélectionner

 sql = "INSERT INTO " + TABLE + "(" + COLUMNS + ") VALUES ('" + 
        		order.getId() + "', '" + 
        		new Timestamp(order.getOrderDate().getTime()) + "', '" + //watch out the time type in the database
        		order.getFirstname() + "', '" + .......

renjunzhou
Messages : 5
Inscription : 06 nov. 2016 17:50

Re: TP04 datetime trouble

Message par renjunzhou » 06 nov. 2016 18:01

oh, and my datatime's type(in class Order) have to be java.util.Data but java.sql.Data or other class will create errors.

dbe
Messages : 13
Inscription : 05 oct. 2015 13:13

Re: TP04 datetime trouble

Message par dbe » 06 nov. 2016 22:50

renjunzhou a écrit :SQL message : Data truncation: Incorrect datetime value: '{SysUpTime = 171116 days 14:5:34} {Timestamp = Sun Nov 06 16:48:33 CET 2016}' for column 'orderdate' at row 1

the older same question in there can't resolve this trouble, and i google it weather because the new edition of mysql change it DATA format

Code : Tout sélectionner

 sql = "INSERT INTO " + TABLE + "(" + COLUMNS + ") VALUES ('" + 
        		order.getId() + "', '" + 
        		new Timestamp(order.getOrderDate().getTime()) + "', '" + //watch out the time type in the database
        		order.getFirstname() + "', '" + .......
Instead of Timestamp object, use a SimpleDateFormat object : new SimpleDateFormat(order.getOrderDate()).format("yyyy-MM-dd HH:mm:ss")

n_ouarti
Messages : 7
Inscription : 22 sept. 2015 17:53

Re: TP04 datetime trouble

Message par n_ouarti » 07 nov. 2016 17:02

However, what you've done should have worked.

If dbe's solution doesn't work either, maybe you should downgrade your mysql and reinstall an older version if you could.

graffion
Messages : 605
Inscription : 21 juin 2005 14:05

Re: TP04 datetime trouble

Message par graffion » 07 nov. 2016 17:37

Hello,

What is you mysql version?

Code : Tout sélectionner

$  /c/wamp/bin/mysql/mysql5.5.20/bin/mysql --version
C:\wamp\bin\mysql\mysql5.5.20\bin\mysql.exe  Ver 14.14 Distrib 5.5.20, for Win32 (x86)

ARequier
Messages : 25
Inscription : 25 oct. 2016 21:08

Re: TP04 datetime trouble

Message par ARequier » 09 nov. 2016 4:19

Hi,
I had the same trouble and I fixed it in the constructor like this:

public Order(final String id, final Date orderdate, final String firstname, final String lastname, final String street1, final String city, final String zipcode, final String country, final Customer customer) {
_id = id;
Date mydate = orderdate;
_orderDate = new Timestamp(mydate.getTime());

_firstname = firstname;
_lastname = lastname;
_street1 = street1;
_city = city; .....

I add to import java.sql.Timestamp;

fazil
Messages : 31
Inscription : 09 oct. 2016 21:28

Re: TP04 datetime trouble

Message par fazil » 09 nov. 2016 16:05

Yop,

bon ben j'ai moi aussi le même problème:
[junit] Testcase: testDomainCreateOrderLine took 2.495 sec
[junit] Caused an ERROR
[junit] Cannot insert data into the database
[junit] com.yaps.petstore.exception.DataAccessException: Cannot insert data into the database
[junit] at com.yaps.petstore.persistence.AbstractDataAccessObject.insert(Unknown Source)
[junit] at com.yaps.petstore.domain.OrderLineDAOTest.createOrderLine(Unknown Source)
[junit] at com.yaps.petstore.domain.OrderLineDAOTest.testDomainCreateOrderLine(Unknown Source)
[junit] Caused by: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime value: 'Wed Nov 09 14:50:59 CET 2016' for column 'orderdate' at row 1


sauf que je n'ai pas réussi à le résoudre avec vos solutions.

J'ai essayé le timestamp dans le Insert:
sql = "INSERT INTO " + TABLE + "(" + COLUMNS + ") VALUES ('" + order.getId() + "', '" + new Timestamp(System.currentTimeMillis())+ "', '" + order.getFirstname() + "', '" + order.getLastname() + "', '" + order.getStreet1() + "', '" + order.getStreet2() + "', '" + order.getCity() + "', '" + order.getState() + "', '" + order.getZipcode() + "', '" + order.getCountry() + "', '" + order.getCreditCardNumber() + "', '" + order.getCreditCardType() + "', '" + order.getCreditCardExpiryDate() + "', '" + order.getCustomer().getId() + "' )";

J'ai essayé dans le constructeur:
this._orderDate = new Date(new Timestamp(System.currentTimeMillis()).getTime())


Ma config: MySQL 5.5

ARequier
Messages : 25
Inscription : 25 oct. 2016 21:08

Re: TP04 datetime trouble

Message par ARequier » 09 nov. 2016 16:11

_oderDtae est une class Date, voici la déclaration:
private Date _orderDate;

Répondre

Qui est en ligne ?

Utilisateurs parcourant ce forum : Aucun utilisateur inscrit et 1 invité