没有 Spring 的 Spring JDBC 模板
是否有像 Spring JDBC Template 这样的 Java 库,具有相同质量的代码和文档以及类似的数据访问异常层次结构,但不依赖于其他 Spring 模块(根据 http://mvnrepository.com/artifact/org.springframework/spring-jdbc/3.0.6。发布)?
Is there Java library like Spring JDBC Template, with same quality of code and documentation and similar data access exceptions hierarchy, but without dependancies on other Spring modules (core/beans/context modules according to http://mvnrepository.com/artifact/org.springframework/spring-jdbc/3.0.6.RELEASE)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Spring-jdbc 直接依赖于以下库:
spring-core
、spring-beans
和spring-tx
。其余的依赖项是可选的,因此您实际上不需要它们。如果这些依赖项对您来说已经很多了,那么您可以看看 Apache DbUtils。
Spring-jdbc has direct dependency to the following libraries:
spring-core
,spring-beans
andspring-tx
. The rest of the dependencies are optional, so you don't need them actually.If these dependencies are already a lot for you, then you might have a look at Apache DbUtils.
对已接受答案的小修正。据我所知,至少还需要一个罐子。它恰好在访问数据访问异常层次结构时发挥作用(底层数据库驱动程序抛出异常并将其包装到 Spring 异常中)。该 jar 是 spring-asm(字节码操作)。
当我的 SQL 查询出现问题并且堆栈跟踪显示类似 MissingClassException 的内容时,我偶然发现了它。
(我宁愿只在答案中添加评论,但看起来我还不符合资格)。
A minor correction to the accepted answer. As far as I can tell there is at least one more jar required. It comes into play exactly when data access exception hierarchy is accessed (an exception is thrown by underlying database driver and it's wrapped into Spring exception). The jar is spring-asm (byte-code manipulation).
I discovered it accidentally when I had a problem in my SQL query and stack trace showed something like MissingClassException.
(I would to prefer just to add a comment to the answer, but it looks I'm not eligible yet).
还有另一种非常接近
JdbcTemplate
的替代方法,您可以使用库sql2o
仅有
slf4j
和guava
依赖项。请参阅下面来自他们网站的简单示例。此外,作为奖励,您仍然可以获得更好的性能,正如您在此基准上看到的那样(披露:我是不是sql2o
项目的成员,我只是在项目中使用它)。There is another alternative way very close to
JdbcTemplate
, you can use the librarysql2o
which has justslf4j
andguava
dependencies. See below a simple example from their web site. Also, as a bonus you still get better performance as you can see on this benchmark (disclosure: I'm NOT a member ofsql2o
project, I'm just using it in a project).