Solution to MySQLSyntaxErrorException when connecting to MySQL using bitronix

Solution to MySQLSyntaxErrorException when connecting to MySQL using bitronix

Solution to MySQLSyntaxErrorException when connecting to MySQL using bitronix

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

3 Analyze the problem

Obviously, the access is denied because there is no permission to access the MySQL database.

When I opened the code, I found that it was true. The code did not provide an account and password for accessing the database.

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);

4. Problem Solving

Add it quickly, the problem is solved O(∩_∩)O~

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

Thank you for reading, I hope it can help you, thank you for your support of this site!

You may also be interested in:
  • How to handle the failure of inserting rare characters in MySQL (Incorrect string value)
  • Solve the problem of Access denied for user ''root''@''%'' to database ''xxx'' after creating a database in MySQL
  • Solution to ERROR 1366 when entering Chinese in MySQL
  • Comparison of MySQL and Oracle SQL Language Differences
  • Examples of using the or statement in MySQL

<<:  A complete tutorial on using axios encapsulation in vue

>>:  How to disable ads in the terminal welcome message in Ubuntu Server

Recommend

Ubuntu installation graphics driver and cuda tutorial

Table of contents 1. Uninstall the original drive...

JavaScript to achieve the effect of clicking on the submenu

This article shares the specific code of JavaScri...

Summary of knowledge points about events module in Node.js

Through the study and application of Node, we kno...

A brief discussion on the implementation principle of Webpack4 plugins

Table of contents Preface know Practice makes per...

Teach you how to quickly install Nginx in CentOS7

Table of contents 1. Overview 2. Download the Ngi...

Analysis of HTTP interface testing process based on postman

I accidentally discovered a great artificial inte...

Vant Uploader implements the component of uploading one or more pictures

This article shares the Vant Uploader component f...

About browser compatibility issues encountered and solutions (recommended)

Preface: Last Sunday, a senior asked me to help m...

Uniapp uses Baidu Voice to realize the function of converting recording to text

After three days of encountering various difficul...

How to use Cron Jobs to execute PHP regularly under Cpanel

Open the cpanel management backend, under the &qu...

Build a server virtual machine in VMware Workstation Pro (graphic tutorial)

The VMware Workstation Pro version I use is: 1. F...

Docker sets up port mapping, but cannot access the solution

#docker ps check, all ports are mapped CONTAINER ...