是否可以使用 JDBC 作为 RDBMS 的抽象层?
JDBC 提供了一个 API,可用于连接到不同的 RDBMS 或类似的数据存储。但数据存储在实现上有所不同(例如 SQL 方言)。
是否可以以这样的方式使用 JDBC,使我的查询和语句适用于最常见的 RDBMS(例如:Oracle、PostgreSQL、SQL Server、MySQL)?
这个问题对我来说很有趣,有两个方面: * 常用SQL(INSERT、UPDATE、SELECT等) * 访问元数据(获取有关表和列的信息)
我目前正在尝试一个自己编写的持久性框架,并希望在其下插入一个 JDBC 数据存储。因此,如果我编写一个 JDBC 数据存储适配器,如果它能在最常见的 RDBMS 上工作,那就太好了。
提前致谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
JDBC是RDBMS 的抽象层。
不幸的是,正如您在问题中已经认识到的那样,抽象是有漏洞的。
如果您坚持使用所有 RDBMS 通用的 SQL 和元数据的一小部分,那就没问题。但实际上,您很可能很快就会超越这些限制。
JDBC is an abstraction layer for RDBMS.
Unfortunately, as you already recognized in your question, the abstraction is leaky.
If you stick to the small subset of SQL and Metadata that is common to all RDBMS, you'll be fine. However in reality, you're very likely to quickly outgrow these limits.
不,这是不可能的,因为它们有两个完全不同的目的。
JDBC 是 DBMS通信协议的抽象,而 SQL 是一种查询语言。
用 SQL 编写的查询使用该通信协议发送到服务器,然后通过该协议返回查询结果(以独立于 DBMS 的方式)。
通信协议和查询之间似乎存在模糊的界限,因为 JDBC API 还指定了从服务器(或结果)检索元数据的调用。但实际上司机可以自由选择任何认为合适的交通工具。这不一定是 SQL 查询。
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 的抽象,与 SQL 的程度大致相同:基本查询足够兼容,但您不断遇到只能使用特定于供应商的功能才能实现的要求:
JDBC works as an abstraction of an RDBMS approximately to the same degree SQL does: basic queries are compatible enough, but you constantly bump into requirements that can only be implemented using vendor-specific features: