我想用 DeleteDbFiles.execute("./data", "mydb", false) 删除 h2 数据库文件,但出现以下错误:org.h2.message.DbException: Cannot delete file "dir/data/mydb.mv.db".
和Caused by: org.h2.jdbc.JdbcSQLNonTransientException: Cannot delete file "dir/data/mydb.mv.db".
我试图关闭 EntityManager em (em.close()) 和 EntityManagerFactory emf (emf.close()) 然后删除文件但仍然出现相同的错误。我试图从 mainForm 中删除 @persistencecontext 但仍然出现相同的错误。这是我的代码:
主要课程:
import...
public class Main {
JalaliCalendar jalaliCalendar = new JalaliCalendar();
EntityManagerFactory emf = Persistence.createEntityManagerFactory("NewPersistenceUnit");
List<LoginEntity> list = new ArrayList<>();
public Main(){
getData();
interance();
}
public void interance(){
if (!list.isEmpty()){
LoginForm loginForm = new LoginForm(list);
loginForm.setTitle("پنجره ورود");
loginForm.setContentPane(loginForm.mainpane);
loginForm.pack();
loginForm.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
loginForm.setLocationRelativeTo(null);
loginForm.setVisible(true);
}else {
Wellcome wellcome = new Wellcome();
wellcome.setTitle("خوش آمدید");
wellcome.setContentPane(wellcome.mainpane);
wellcome.pack();
wellcome.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
wellcome.setLocationRelativeTo(null);
wellcome.setVisible(true);
}
}
public void getData(){
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
Query query = em.createQuery("from LoginEntity ");
list = query.getResultList();
em.getTransaction().commit();
em.close();
}
public void getDiff(){
JalaliCalendar j1 = new JalaliCalendar();
j1.setYear(1398);
j1.setMonth(3);
j1.setDay(5);
JalaliCalendar j2 = new JalaliCalendar();
j2.setYear(1398);
j2.setMonth(2);
j2.setDay(5);
}
湖上湖
相关分类