jdbc mysql 锁,为什么我得到SQLException:数据库被锁定在我的JDBC SQLite数据库上?...

I have a single-threaded application that uses 3 SQLite databases in 3 different files on the local file system.

I have created a DbAdapter helper class that opens the connection to the SQLite database file. In this class I have an open method that creates the connection, and a close method that releases everything.

The 3 databases are accessed from a class that derives DbAdapter.

In my program every database access look like this:

MyDbAdapter DB = new MyDBAdapter();

int stuff = DB.getStuff(); // queries the database

DB.close();

// now do something with `stuff`

I have logged to stdout all calls to DbAdapter.open and DbAdapter.close. Everytime there's an open(), a close() follows close by.

I also take the care to close all my Statements (which will cause the associated ResultSets to be closed aswell).

So I guess that my database accesses are clean because I'm trying to get them as short as possible, and I release all the resources as soon as I no longer need them.

Yet, I'm still getting a java.sql.SQLException: database is locked.

Is there anything that I'm not doing properly? I know I haven't shown any code, but I'd have to post a LOT of code and it won't be relevant. I'm just asking if I'm using the best practises here, because I think I do and I'm still getting exceptions.

This is with Java 1.6, Xerial.org's sqlite-jdbc-3.7.2 driver, on Mac OS 10.6 x64

解决方案

I noticed that I had strange Java processes that I couldn't kill. I ran:

ps aux | grep java | grep -v grep | awk '{print$2}' | xargs sudo kill -9

But those processes were still here (with same PID).

I rebooted, and the problem doesn't appear anymore. This doesn't make sense because I was able to make a lot of DB calls without any crash, there was just one single call that caused the exception. I don't understand at ALL what happened, but I'm no longer having this issue.

Any real answer welcome.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值