bitronix 連接 MySQL 出現(xiàn)MySQLSyntaxErrorException 的解決方法
1. 開發(fā)環(huán)境
hibernate 版本:5.1.0.Final
Bitronix btm 版本:2.1.3
2 異常堆棧信息
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 分析問題
很明顯是因?yàn)闆]有訪問 MySQL 數(shù)據(jù)庫的權(quán)限,導(dǎo)致訪問被拒絕。
打開代碼一看,果然是這樣,代碼里沒有提供訪問數(shù)據(jù)庫的賬號和密碼嘛
ds.setClassName("bitronix.tm.resource.jdbc.lrc.LrcXADataSource");
ds.getDriverProperties().put(
"url",
connectionURL != null ? connectionURL
: "jdbc:mysql://localhost:3306/hibernate?useUnicode=truecharacterEncoding=UTF-8zeroDateTimeBehavior=convertToNull"
);
Properties dp=ds.getDriverProperties();
dp.put("driverClassName", "com.mysql.jdbc.Driver");
ds.setDriverProperties(dp);
4 解決問題
趕緊加上,問題解決 O(∩_∩)O~
...
dp.put("user","root");
dp.put("password","");
...
ds.setDriverProperties(dp);
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
您可能感興趣的文章:- MySQL生僻字插入失敗的處理方法(Incorrect string value)
- 解決mysql創(chuàng)建數(shù)據(jù)庫后出現(xiàn):Access denied for user ''root''@''%'' to database ''xxx''的問題
- mysql輸入中文出現(xiàn)ERROR 1366的解決方法
- MySQL與Oracle SQL語言差異比較一覽
- MySQL中or語句用法示例