如何从外部 java 应用程序连接到 glassfish 中配置的数据库?

发布于 2024-09-10 10:26:21 字数 201 浏览 6 评论 0原文

标题几乎说明了一切,但这里有一些背景知识。

我们在 glassfish 中配置了一个数据库,由部署在 glassfish 上的网站访问,我们还从外部 java 应用程序访问数据库,我发现这可能有点低效,因为我们从外部应用程序打开了很多与数据库的连接。所以我想知道我们是否可以通过 glassfish 的连接池访问数据库?

提前致谢。

皮尔斯

The title pretty much says it all, but here's some background.

We have a database configured in glassfish accessed by a website deployed on glassfish, we also access the database from an external java application, it occurred to me that this could be somewhat inefficient since we open quite a few connections to the database from our external app. So I was wondering if we could somehow access he database through glassfish's connection pool?

Thanks in advance.

Piers

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

素衣风尘叹 2024-09-17 10:26:21

你必须尝试一下这个。

http://javahowto.blogspot.com/2006/08/ access-glassfish-datasource-remotely.html 建议可以通过 JNDI 从独立客户端查找连接池。实际的客户端代码示例在 http: //javahowto.blogspot.com/2006/08/access-jboss-datasource-remotely-from.html#client

You'll have to try this.

http://javahowto.blogspot.com/2006/08/access-glassfish-datasource-remotely.html suggests it is possible to look up the connection pool via JNDI from a standalone client. An actual client code example is given at http://javahowto.blogspot.com/2006/08/access-jboss-datasource-remotely-from.html#client

溇涏 2024-09-17 10:26:21

只有当您的外部应用程序与 glassfish 在同一虚拟机中运行时,这才可能实现。 “外部”一词表示:不,不可能。

请注意,数据库设计用于处理大量连接。这是它们存在的主要原因之一:允许多个程序同时处理相同的数据。

That would only be possible if your external application was running in the same VM as glassfish. The word "external" says: Nope, not possible.

Note that databases are designed to handle lots of connections. That's one of the main reasons why they exist: To allow several programs at once to work on the same data.

空名 2024-09-17 10:26:21

如果您的程序不在 glassfish 上运行,我认为您无法访问该池。
与数据库的一些连接应该不会太重要,至少如果它们不经常创建和销毁的话。如果是这种情况,您也可以在外部应用程序中构建一个池。

I don't think you can access the pool, if your program does not run on glassfish.
A few connections to the database shouldn't matter too much, at least if the aren't created and destroyed very often. You could build a pool in your external application as well, if that is the case.

小霸王臭丫头 2024-09-17 10:26:21

好吧,我正在回答我自己的问题,这不是一个出色的答案,但它确实满足了我的问题的要求。

您可以做的是从外部 java 应用程序连接到 EJB,如果 bean 提供对数据库的访问,那么通过使用它,您将利用 glassfish 提供的连接池。

您可以在此处找到有关如何执行此操作的信息

- https://glassfish.dev .java.net/javaee5/ejb/EJB_FAQ.html

就效率而言,我不确定这是否是一个好主意,因为它可能会给您的 Web 应用程序带来过度的压力,在我最初的想法中,我想完全绕过网络应用程序并直接与 glassfish 通信,对此的任何评论将不胜感激。

Well I'm answering my own question, and it's not a brilliant answer but it does sort of fulfil the requirements of my question.

What you can do is connect to an EJB from an external java application, if the bean provides access to your database then by using it you will be making use of the connection pooling provided by glassfish.

You can find info on how to do this

here - https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html

In terms of efficiency I'm not sure if this is a good idea since it may put excess strain on your web application, in my initial idea I was thinking to bypass the webapp completely and communicate directly with glassfish, any comments on this would be appreciated.

安静 2024-09-17 10:26:21

另一种选择是向 Glassfish 数据访问对象添加 Web 服务。

然后,您可以通过 SOAP 或 REST 调用访问数据库。

Another option is to add a web service to your Glassfish data access object.

You could then access the database with SOAP or REST calls.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文