java - Overwrite existing file -
i want overwrite 2 files. both files store information in memory database (hsqldb): db.data , db.script
my following code should this:
public class dbreset { public path db_data = paths.get("db_sep/db_backup/db.data"); public path db_script = paths.get("db_sep/db_backup/db.script"); public path dest_data = paths.get("db_sep/db.data"); public path dest_script = paths.get("db_sep/db.script"); public void discard() throws ioexception { files.copy(this.db_data, this.dest_data, standardcopyoption.replace_existing); files.copy(this.db_script, this.dest_script, standardcopyoption.replace_existing); } } however if use
public class anotherclass { new dbreset.discard(); // db new dbreset.discard(); // other db } the second discard() not overwrites files.
i use discard() reset database original state. please don't ask / tell me there other ways reset database, actual problem why not overwrite files.
sadly shutdown not work.
public void discard() throws ioexception, sqlexception { connection c = dbconnectfactory.getdatasource.getconnection(); preparedstatement ps = c.preparedstatement("shutdown"); ps.executeupdate(); ps.close(); c.close(); files.copy(this.db_data, this.dest_data, standardcopyoption.replace_existing); files.copy(this.db_script, this.dest_script, standardcopyoption.replace_existing); } throws @ first line of connection c = dbconnectfactory.getdatasource.getconnection(); java.sql.exception: error in script file line: 1 unknown token: ... lots of unknown sources.
also tested in runquery(string query) - opens connection , executes given query via preparedstatement - force shutdown, throws same error above, should connection @ getconnection().
what want is:
- restore original db instance.
- do stuff db,
select,insert, assertions. test stuff against database. - restore original db instance.
- do other tests against database.
ps: i'm using hsqldb in file mode.
Comments
Post a Comment