可以将JDBC用作RDBMS的抽象层吗? [英] Is it possible to use JDBC as an abstraction layer for RDBMS?

查看:97
本文介绍了可以将JDBC用作RDBMS的抽象层吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JDBC提供了一个API,可用于连接到不同的RDBMS或类似的数据存储。但是数据存储区的实现方式有所不同(例如SQL方言)。



是否可以以这种方式使用JDBC,以便我的查询和语句可以在大多数常见的RDBMS(例如Oracle,PostgreSQL,SQL Server,MySQL)上工作? / p>

这个问题在两个方面对我来说都很有趣:
*通用SQL(INSERT,UPDATE,SELECT等)
*访问元数据(获取有关表和列的信息)



我目前正在尝试使用自写持久性框架,并希望在其下插入JDBC数据存储。因此,如果我编写JDBC数据存储区适配器,那将很好,并且可以在大多数常见的RDBMS上使用。



预先感谢

解决方案

这不可能,因为它们有两个完全不同的目的。



JDBC是DBMS 通信协议的抽象,而SQL是查询语言。



使用该通信协议将用SQL编写的查询发送到服务器,然后通过该协议(以DBMS独立的方式)返回查询结果。 / p>

由于JDBC API还指定了从服务器(或从结果)检索元数据的调用,因此通信协议和查询之间似乎存在模糊的界限。但是实际上,驾驶员可以自由使用任何认为合适的交通工具。不一定需要是SQL查询。


JDBC provides an API, which may be used to connect to different RDBMS or similar datastores. But the datastores differ in implementation (e.g. SQL dialects).

Is it possible to use JDBC in such a way, that my queries and statements work on most common RDBMS (e.g.: Oracle, PostgreSQL, SQL Server, MySQL)?

That question is interesting for me at two aspects: * Common SQL (INSERT, UPDATE, SELECT etc.) * Accessing Meta data (getting information about tables and columns)

I am currently experimenting with an self written persistence framework and want to plug a JDBC datastore under it. So if I write a JDBC datastore adapter, it would be nice, if it would work on most common RDBMS.

Thanks in advance

解决方案

No this is not possible because they serve two completely different purposes.

JDBC is an abstraction of the DBMS communication protocol, whereas SQL is a query language.

The queries written in SQL are sent to the server using that communcation protocol and the results of the queries are then returned through that protocol (in a DBMS independent way).

There seems to be a blurry line between the communication protocol and the queries as the JDBC API also specifies calls to retrieve meta data from the server (or from the result). But actually the driver is free to use any means of transportation that deems suitable. That does not necessarily need to be a SQL query.

这篇关于可以将JDBC用作RDBMS的抽象层吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆