用于数据库操作的 Java 框架
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5878539/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java Framework for Database operations
提问by Amit Kumar Gupta
At my work place, we use DAO pattern to hancle any sort of database operation. It hides bulky statements from programmer. Programmers need to write sql query and logic to handle output data. BaseDao handles all sort of operation and return output in required format.
在我的工作场所,我们使用 DAO 模式来处理任何类型的数据库操作。它对程序员隐藏了大量语句。程序员需要编写sql查询和逻辑来处理输出数据。BaseDao 处理所有类型的操作并以所需格式返回输出。
I found that this class is not perfect. I added the code to control number of connections and to handle connection issues like slow connectivity, no connectivty, number of atttempts for connection etc.
我发现这门课并不完美。我添加了代码来控制连接数并处理连接问题,如连接缓慢、无连接、连接尝试次数等。
But I would have to add more code to support advance feature of JDBC like providing/accessing binary data, Handling resultsets returned from SPs etc.
但是我必须添加更多代码来支持 JDBC 的高级功能,例如提供/访问二进制数据、处理从 SP 返回的结果集等。
Is there any Java Framework or group of classes which can cover many of the database operations?
是否有任何 Java 框架或一组类可以涵盖许多数据库操作?
Please suggest.
请建议。
采纳答案by Jonas
I think that you are looking for Java Persistence API. It's a Java EE specification and Hibernateis the most popular implementation.
我认为您正在寻找Java Persistence API。它是 Java EE 规范,Hibernate是最流行的实现。
回答by qwerty
You could try Spring DAOinstead. They have a nice template pattern for handling resultsets.
你可以试试Spring DAO。他们有一个很好的模板模式来处理结果集。
回答by Olaf
Or you can take another step step back away from JDBC and use Hibernate.
或者,您可以从 JDBC 再退一步并使用 Hibernate。
回答by CorayThan
Spring Data JPAdoes even more abstraction than the other suggestions people have made. With that and Hibernate you don't even need to write queries unless it's a complex operation you need to perform.
Spring Data JPA比人们提出的其他建议更抽象。有了它和 Hibernate,您甚至不需要编写查询,除非它是您需要执行的复杂操作。