jboss 如何在含有“="的密码中使用转义符?

l3zydbqr  于 2022-11-08  发布在  其他
关注(0)|答案(1)|浏览(149)

我正在为我的应用程序使用microsoft sql数据库,该应用程序部署在jboss服务器中。数据库密码包含类似_i9wexp=tfd的内容。此密码在普通java类方法和我的本地jboss dev studio数据源配置中运行良好
本地jboss独立xml文件中的我的数据源配置

<datasource jndi-name="java:jboss/datasources/Star-DS" pool-name="Star-DS" enabled="true" use-java-context="true">
          <connection-url>jdbc:sqlserver://server_name;DatabaseName=DB_NAME</connection-url>
          <driver>sqljdbc</driver>
          <security>
                    <user-name>DB_USER_NAME</user-name>
                    <password>_i9wexp=tfd</password>
          </security>
  </datasource>

这在连接服务器数据库的本地开发中工作正常。但是当从部署了应用程序的jboss服务器连接并从下面的www.example.com文件指向数据库连接时datasource.properties:

connection-url=jdbc:sqlserver://server_name;DatabaseName=DB_NAME
jndi-name=java:jboss/datasources/Star-DS
driver-name=custom.mssql.default
user=DB_USER_NAME
password=_i9wexp=tfd

当我部署应用程序并在浏览器中打开应用程序时,我在日志中看到以下错误:

Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'DB_USER_NAME'. ClientConnectionId:62fc2ccd-9af6-4c3d-872c-eeb5376204bc
    at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:216)
    at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:254)
    at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:84)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:2926)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:2243)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:42)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:2229)
    at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5696)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1716)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1327)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:992)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:828)
    at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1012)
    at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.getLocalManagedConnection(LocalManagedConnectionFactory.java:296)
    ... 28 more

09:40:38,508 WARN  [org.hibernate.engine.jdbc.internal.JdbcServicesImpl] (ServerService Thread Pool -- 60) HHH000342: Could not obtain connection to query metadata : javax.resource.ResourceException: IJ000453: Unable to get managed connection for java:jboss/datasources/Star-DS
09:40:38,512 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 60) MSC000001: Failed to start service jboss.persistenceunit."star.ear/starWeb.war#Star": org.jboss.msc.service.StartException in service jboss.persistenceunit."star.ear/starWeb.war#Star": javax.persistence.PersistenceException: [PersistenceUnit: Star] Unable to build EntityManagerFactory
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:103)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_60]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_60]
    at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_60]
    at org.jboss.threads.JBossThread.run(JBossThread.java:122) [jboss-threads-2.1.1.Final-redhat-1.jar:2.1.1.Final-redhat-1]
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: Star] Unable to build EntityManagerFactory
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:924)
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:899)
    at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:76)
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:200)
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.access$600(PersistenceUnitServiceImpl.java:57)
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:99)
    ... 4 more
Caused by: org.hibernate.HibernateException: Connection cannot be null when 'hibernate.dialect' not set
    at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:98)
    at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:68)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:170)
    at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:85)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:184)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:156)
    at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1825)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1783)
    at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:96)
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:914)
    ... 9 more

它也成功地登录了sql server management studio。
如何在通过应用程序连接数据库时使用转义符访问此密码?
我用_i9wexp\=tfd试过类似的方法,但也失败了。有人能帮我解决这个问题吗?

gcuhipw9

gcuhipw91#

尝试将密码放在大括号中。因此,如果您的密码是_i9wexp=tfd,请尝试
...;password={_i9wexp=tfd}
如果您的密码包含右花括号},则必须 * 另外 * 通过将其加倍来转义这些括号:
abcd;{} =〉{abcd;{}}}
我们可以看到,在密码的开头添加了一个{,在密码的结尾添加了一个},并且在密码的内容中还添加了转义的}(而密码中的左大括号保持不变)。
花括号部分已经在这里以一种很好的方式进行了描述:https://stackoverflow.com/a/55151212/13249425

相关问题