java - Execute db statements from file -


i use embedded apache derby application. have sql script called createdb.sql creates tables in database , populates initial data, e.g.:

set schema app;   create table study (     study_id    bigint  not null generated identity  (start 1, increment 1),     name        varchar(50) not null,     note         varchar(1000) default '',           created timestamp default current_timestamp,     deleted boolean default false,     unique(name),     constraint primary_key primary key (study_id)  );  insert "app"."study" (name) values ('default');    create table img (     img_id bigint not null generated identity  (start 1, increment 1),     filename varchar(200) not null,     path        varchar(300) not null,     flipped boolean default false,     type      smallint not null,      note varchar(1000) default '',     created timestamp default current_timestamp,     primary key (img_id)     );  alter table img add column dpix integer default -1; alter table img add column dpiy integer default -1; 

the question how load file , execute statements using java? i'm trying different function don't work. example,

statement s = conn.createstatement(); s.execute(sqlstr); 

or

statement s = conn.createstatement(); s.executeupdate(sqlstr); 

where sqlstr string variable containing contents of createdb.sql file. how execute sql commands contained in script can create tables , initialize them? btw, sql script works, use in squirrel sql client manualy create , initialize database. within application.

the below tutorial give how run mysql script(.sql file) . have change mysql db connection derby db , run. work.

http://www.mkyong.com/jdbc/how-to-run-a-mysql-script-using-java/

here alternative way run mysql script without using third party library.

http://coreyhulen.wordpress.com/2010/04/07/run-a-sql-script-for-mysql-using-java/


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -