gpt4 book ai didi

sql-server - Tomcat JNDI 数据源设置自己的数据库密码

转载 作者:行者123 更新时间:2023-11-28 23:44:56 24 4
gpt4 key购买 nike

目前我的系统运行如下外部 JNDI 连接:

在我的 context.xml 中:

<Context>
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Resource name="jdbc/sql" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30"
maxWait="10000" username="sa" password="sa" driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
url="jdbc:sqlserver://localhost\sqlexpress:1433;databaseName=Agent_DB">
</Context>

我的java代码:

Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/sql");
if (envContext == null) throw new Exception("Error: No Context");
if (ds == null) throw new Exception("Error: No DataSource");
if (ds != null) conn = ds.getConnection();`

如您所见,连接到数据库的密码已在我的 context.xml 中设置。有什么办法可以在我的 java 代码中设置数据库密码?原因是由于安全问题,密码必须加密,所以我需要在我的 Java 代码中解密它以便 getConnection()。

最佳答案

当然,只需将它从 context.xml 中删除并使用 DataSource.getConnection(username, password)。

关于sql-server - Tomcat JNDI 数据源设置自己的数据库密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15516977/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com