最佳答案
(我是jDBI的主要作者)
jDBI是建立在 JDBC 之上的便利库. JDBC 工作得很好,但通常似乎针对用户的数据库供应商(驱动程序编写者)进行了优化。 jDBI 尝试公开相同的功能,但在为用户优化的 API 中。
它比 Hibernate 之类的级别低得多或 JPA .最接近的类似库可能是 MyBatis (iBATIS 的 fork 继承者)。
jDBI 支持两种样式 API,一种较旧的 fluent 样式,如下所示:
List<Something> r = h.createQuery("select * from something where name = :name and id = :id")
.bind(0, "eric")
.bind("id", 1)
.map(Something.class)
.list();
较新的 SQL 对象 API 做了更多反射类型的东西,并且确实开始抽象一堆 JDBC 东西:
interface TheBasics
{
@SqlUpdate("insert into something (id, name) values (:id, :name)")
int insert(@BindBean Something something);
@SqlQuery("select id, name from something where id = :id")
Something findById(@Bind("id") long id);
}
@Test
public void useTheBasics() throws Exception
{
TheBasics dao = dbi.onDemand(TheBasics.class);
dao.insert(new Something(7, "Martin"));
Something martin = dao.findById(7);
}
该库在 http://jdbi.org/ 上有很好的引用文档 (javadoc) 和一些合理的教程风格文档.它自 2004 年以来一直存在,并且被相对较少的人使用(我个人认识的几十个人,可能还有十几家公司),但对他们来说效果很好。大多数从事它工作的人都是 A+ 人员,主要关心的是构建一个适合他们的工具——它是开源的,这在很大程度上是一个副作用。
关于java - JDBC和JDBI有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5819392/