Apache Derby ID column should auto increment one by one - but it does not, why?

余生长醉 提交于 2019-12-02 03:35:29

Gaps in the generated sequence numbers are a correct and documented behavior of Derby.

See, for example, https://db.apache.org/derby/docs/10.9/ref/rrefproperpreallocator.html

And: https://issues.apache.org/jira/browse/DERBY-5151

As Described by Bryan, this error is well known. But good thing is you can solve it by using:

DriverManager.getConnection("jdbc:derby:;shutdown=true");

This will shutdown all the databases that you have in derby, you can always specify the database you want to shutdown.

DriverManager.getConnection("jdbc:derby:" + HOME_DIRECTORY + "\\MyDB;shutdown=true")

the problem is we have to shut down the derby db whenever we are sign out or closing our application,then only the values will be inserted properly otherwise the cache values prevents the exact insertion value in database table.

follow below steps:

con = DriverManager.getConnection("jdbc:derby:" + "db" + ";create=true");->this is for loading derby db by mentioning 'db' name.this code we have to place in your application login action.

DriverManager.getConnection("jdbc:derby:"+"db"+";shutdown=true");->this is for closing the database 'db'.we have to place this code in your application logout action or closing place.

note : This is for Embedded DB

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!