配置tomcat的jndi,关于goldenDB
时间: 2023-03-02 07:54:22 浏览: 109
为了配置Tomcat的JNDI数据源,您需要进行以下步骤:
1. 在Tomcat的安装目录下找到“conf”文件夹,然后打开“context.xml”文件。
2. 在文件中添加以下内容:
```
<Resource name="jdbc/goldenDB" auth="Container" type="javax.sql.DataSource"
maxTotal="100" maxIdle="30" maxWaitMillis="10000"
username="[username]" password="[password]" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://[host]:[port]/[database_name]"/>
```
其中,“[username]”、“[password]”、“[host]”、“[port]”和“[database_name]”需要替换为相应的数据库信息。
3. 在您的应用程序的web.xml文件中,添加以下内容:
```
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/goldenDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
```
这样,您就可以在您的Java代码中通过JNDI访问“goldenDB”数据库了。