简体   繁体   中英

ORMLite on an existing database

I want to use ORMLite but I already have a database with existing data. Will I have problems if I start using ORMLite? Will it retrieve my data correctly by using the good column and table name?

My date type was saved like that: yyyy-MM-dd HH:mm:ss

So when I implemented ORMLite I did this:

@DatabaseField(columnName = KEY_DATEENVOIE_SENDLEAD, dataType = DataType.DATE_STRING, format = "yyyy-MM-dd HH:mm:ss")
private Date dateEnvoieSendLead;

Nos when I do queryForAll, I print this:

Mon Feb 06 16:03:57 GMT+01:00 2017

Will it retrieve my data correctly by using the good column and table name?

You can certainly start using ORMLite even if you have existing data in your database. The trick is to match the table names and column types and names precisely. You will use the @DatabaseTable(tableName = "...") and change the ... to correspond to your existing table name. Then set the column names of fields with @DatabaseField(columnName = "...") so that the .. matches each of your fields.

The only tough part will come if you have some sort of custom data in your columns and you don't want it to be a String field. For example, you might store a Date field in a special format in your database. In that case you will have to spend more time making sure the format is correct or possibly having to use custom field persisters .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM