简体   繁体   English

如何从context.xml资源获取URL

[英]How do I get the URL from context.xml resource

I am using a JNDI DataSouce with Tomcat. 我正在将JNDI DataSouce与Tomcat一起使用。

my context.xml for java web app has a resource ta that looks like this : 我的Java Web应用程序context.xml具有如下所示的资源ta:

<Resource
        name="jdbc/dbv1RW" type="javax.sql.DataSource"
        maxActive="100" maxIdle="30" maxWait="10000" 
        url="jdbc:mysql://localhost:3306/dbv1"
        driverClassName="com.mysql.jdbc.Driver"
        username="root" password="root"
 />

And I fetch the data source in my java class like this : 然后像这样在我的java类中获取数据源:

Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
dataSource = (DataSource) envCtx.lookup("jdbc/dbv1RW");

How can I get the URL of the data source without establishing the connetion with the data source(ie without calling the get connection method) ? 如何在不与数据源建立连接的情况下(即不调用get连接方法)获取数据源的URL?

You have to printout what is the real implementation of the returned data source. 您必须打印出返回数据源的真正实现是什么。 If the implementation exposes the parameters then you can cast it to its real type and access them. 如果实现公开参数,则可以将其强制转换为实型并访问它们。 It will be implementation (server) specific. 这将是特定于实现(服务器)的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM