简体   繁体   English

Java嵌入式数据库(java db / derby)连接管理

[英]Java embedded database (java db / derby) connection management

I'm creating a desktop application to record the results of various football tournaments. 我正在创建一个桌面应用程序,以记录各种足球比赛的结果。 I'm using Java DB as my embedded database. 我正在使用Java DB作为嵌入式数据库。 My question is what would be appropriate to handle the database connection management that I can use instead of creating and destroying a connection each time I want to read/write to the database? 我的问题是什么才适合处理我每次想对数据库进行读/写时可以使用的数据库连接管理,而不是创建和销毁连接? Most examples/tutorials I can find are very simple, having just a couple of methods that simply create a table, add some data, read some data, end the program. 我可以找到的大多数示例/教程都非常简单,只有几个方法可以简单地创建表,添加一些数据,读取一些数据并结束程序。 I would like what I am creating to be a bit more robust to use, and performant enough to not irritate my end users. 我希望所创建的内容使用起来更加健壮,并且性能足以不激怒最终用户。

Any information etc would be greatly appreciated. 任何信息等将不胜感激。 For reference I'm using Java 8 jdk (oracle) with Intellij. 作为参考,我将Java 8 jdk(oracle)与Intellij结合使用。

Cheers, Stu 干杯,斯图

As Elliot answered, the best way is to use connection pool. 正如Elliot回答的那样,最好的方法是使用连接池。 There are many pools on the market, some are bad, some good. 市场上有很多游泳池,有些不好,有些很好。 For Java 8 and newest jdbc drivers, the one I would recommend ( but other choices are can be good as well) HikariCP, see https://github.com/brettwooldridge/HikariCP#initialization how to use it. 对于Java 8和最新的jdbc驱动程序,我会推荐(但其他选择也可以)HikariCP,请参见https://github.com/brettwooldridge/HikariCP#initialization如何使用它。 Other popular choice is tomcat pool or c3p0 which is slower but very mature and robust. 其他流行的选择是tomcat pool或c3p0,它速度较慢,但​​非常成熟且健壮。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM