java - want to check if a table exists before making transaction -
i writing application using java , sqlite database. making many inserts database. each time before inserting have used following sql statement , executed using java
create table if not exists table_name " + " (id int not null, " + " percent int not null, " + " task_data varchar(1000) ," + " constraint pk_progressid primary key (id))
however not practice execute statement each time. alternative such checks table exists or not , creates if doesn't?
database migration
this problem called “database migration”. on every database connection made app, need know database structure , data in known expected condition , configuration.
one solution internally label current state of database, sort of version number. of course database table might perfect place store versioning info.
i go on , guide through kinds of versioning do, how have app run sql scripts , java code needed bring instance of database up-to-date current latest expectations. no need me explanation.
two projects have been built these chores of database migration. no code write! either of these projects can plugged app.
every time app connects database checks latest known versioning info stored in table. if db instance out-of-date, these tools run sql scripts and/or java code needed create/modify table definitions, insert/modify/delete rows, , on.
of course must write, test, , archive sql scripts , updating java code develop project.
Comments
Post a Comment