B4J Question B4J MySQL Connection

Declan

Well-Known Member
Licensed User
Longtime User
I am trying to connect to a MySQL database with:
B4X:
sql1.Initialize2("com.mysql.jdbc.Driver", "jdbc:mysql://197.189.232.202/trolley?characterEncoding=utf8","root","Hello!@#$%")

I receive this error:
B4X:
2017-09-07 13:34:17.459:INFO::main: Logging initialized @234ms
main._appstart (java line: 63)
java.sql.SQLException: Access denied for user 'root'@'the031_truserv_' (using password: YES)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3973)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3909)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:873)
    at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1710)
    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1226)
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2205)
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2236)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2035)
    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:790)
    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
    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:425)
    at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:400)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:247)
    at anywheresoftware.b4j.objects.SQL.Initialize2(SQL.java:56)
    at b4j.example.main._appstart(main.java:63)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:77)
    at b4j.example.main.main(main.java:29)
 

DonManfred

Expert
Licensed User
Longtime User
java.sql.SQLException: Access denied for user 'root'@'the031_truserv_' (using password: YES)
Seems the password does not match the username root
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
@Declan: Could you please post your solution? Just in case someone has the same error, searches this forum and is not left with a "Thanks sorted" answer.
 
Upvote 0

Declan

Well-Known Member
Licensed User
Longtime User
I am connecting to my MySQL database from a B4J Server app.
Where I made the mistake was that both the B4J Server and the MySQL db are on the same machine.
Instead of connecting to the IP, I just connect to "localhost"
 
Upvote 0
Top