Domanda

I'm running ORMlite on Android app. I have created a @DatabaseTable class with a Timestamp field.

@DatabaseTable
public class Cliente {
    @DatabaseField
    private Timestamp dateinicio;
}

I can insert items but when I try to recover data I get this error:

java.sql.SQLException: Could not assign object 'Wed Jan 29 13:35:01 CET 2014'
    to field FieldType:name=dateinicio,class=Cliente

I suppose this must be a typical error but I cannot resolve it.

È stato utile?

Soluzione

Is this existing data you are trying to get to work or did ORMLite store this date for you? Either way you are going to have to match the formats that Sqlite supports.

Internally ORMLite uses "yyyy-MM-dd HH:mm:ss.SSSSSS". You can specify the format using something like the following where the ... is replaced with the format which matches your data.

@DatabaseField(format = "...")
private Timestamp dateinicio;

Sqlite officially supports the following date formats.

  • YYYY-MM-DD
  • YYYY-MM-DD HH:MM
  • YYYY-MM-DD HH:MM:SS
  • YYYY-MM-DD HH:MM:SS.SSS
  • YYYY-MM-DDTHH:MM
  • YYYY-MM-DDTHH:MM:SS
  • YYYY-MM-DDTHH:MM:SS.SSS
  • HH:MM
  • HH:MM:SS
  • HH:MM:SS.SSS
  • now
  • DDDDDDDDDD

See this answer here: ORMLite query date format issue

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top