Home > Database > Mysql Tutorial > body text

Solution to MySQLSyntaxErrorException error when parsing bitronix connection to MySQL

怪我咯
Release: 2017-04-30 10:20:53
Original
1673 people have browsed it

This article mainly introduces the relevant information about the solution to the MySQLSyntaxErrorException when bitronix connects to MySQL. Friends who need it can refer to

The solution to the MySQLSyntaxErrorException when bitronix connects to MySQL

1. Development environment

hibernate version: 5.1.0.Final
Bitronix btm version: 2.1.3

2 Exception stack information

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Access denied for user ''@'localhost' to database 'hibernate'
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
  at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
  at com.mysql.jdbc.Util.handleNewInstance(Util.java:377)
  at com.mysql.jdbc.Util.getInstance(Util.java:360)
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:978)
  at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3887)
  at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3823)
  at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:870)
  at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1659)
  at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1206)
  at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2234)
  at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2265)
  at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2064)
  at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:790)
  at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
  at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
  at com.mysql.jdbc.Util.handleNewInstance(Util.java:377)
  at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:395)
  at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:325)
  at bitronix.tm.resource.jdbc.lrc.LrcXADataSource.getXAConnection(LrcXADataSource.java:104)
  ... 33 more
Copy after login

3 Analysis of the problem

It is obviously because there is no permission to access the MySQL database , causing access to be denied.

Open the code and see that it is indeed the case. The account and password for accessing the database are not provided in the code

ds.setClassName("bitronix.tm.resource.jdbc.lrc.LrcXADataSource");
          ds.getDriverProperties().put(
              "url",
              connectionURL != null ? connectionURL
                  : "jdbc:mysql://localhost:3306/hibernate?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull"
          );
          Properties dp=ds.getDriverProperties();
          dp.put("driverClassName", "com.mysql.jdbc.Driver");
          ds.setDriverProperties(dp);
Copy after login

##4 Solution Question

Hurry up and add it, the problem is solved O(∩_∩)O~

...
dp.put("user","root");
dp.put("password","");
...
ds.setDriverProperties(dp);
Copy after login

The above is the detailed content of Solution to MySQLSyntaxErrorException error when parsing bitronix connection to MySQL. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template