读取 Jta 数据源

发布于 2024-12-26 07:25:06 字数 331 浏览 3 评论 0原文

我有一个 JSF、EclipseLink 应用程序。我使用 JasperReports 来导出我需要创建连接的报告。

JasperPrint jasperPrint = JasperFillManager.fillReport(File, Hash Map, Connection)

我无法访问当前连接(我在持久性 xml 中定义的数据源)。我尝试了不同的方法,但唯一有效的是创建新的连接。 我对在代码中对连接参数进行硬编码感觉不太好。 有没有办法读取数据源的参数,以便我可以使用相同的参数创建连接?

I have a JSF, EclipseLink app. I use JasperReports, to export a report I need to create a connection.

JasperPrint jasperPrint = JasperFillManager.fillReport(File, Hash Map, Connection)

I cant access my current connection (The datasource I define in the persistence xml). I have tried different ways, but the only thing that has worked is creating a new connection.
I dont feel really good about hard coding the connection parameters in my code.
Is there a way I can read the parameters of the datasource, so I can create the connection with the same parameters?

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

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

发布评论

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

评论(1

月朦胧 2025-01-02 07:25:06

我不确定您的意思是您无法从 persistence.xml 访问连接,就好像您正在使用数据源一样,它是在其他地方定义的,并且 persistence.xml 用于定义提供程序应如何从容器获取它。因此,如果它是数据源,持久单元将不会有任何有关连接本身的信息,但您应该能够从容器中查找它。

您可以按照此处所述从 EclipseLink 获取连接:
http://wiki.eclipse.org/EclipseLink/Examples/JPA/EMAPI#Getting_a_JDBC_Connection_from_an_EntityManager

您还可以使用此代码从会话中获取登录对象,如果您不使用登录对象,该对象将包含连接信息数据源。

I'm not sure what you mean you cannot access the connection from persistence.xml as if you are using a datasource, it is defined elsewhere and the persistence.xml is used to define how the provider should get it from the container. So if it is a datasource, the persistence unit will not have any information on the connection itself, but you should be able to look it up from the container.

You can get the connection from EclipseLink as described here:
http://wiki.eclipse.org/EclipseLink/Examples/JPA/EMAPI#Getting_a_JDBC_Connection_from_an_EntityManager

You can also use this code to get the login object from the session, which will contain the connection information if you are not using a datasource.

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