Android Question Mysql connect

tanush62

Member
I'm trying to connect to mysql server on local nettwork. What I'm doing wrong?

Code:
#AdditionalJar: mysql-connector-java-5.1.34-bin.jar
'.......


    Public mysql As JdbcSQL

    user = "someuser"
    pass = "password"

    Try
        mysql.Initialize2("com.mysql.jdbc.Driver", "jdbc:mysql://192.168.0.11/information_schema", user, pass)
    Catch
        Log(LastException.Message)
        appas = False
    End Try

I got the error:
Code:
java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object java.util.Map.get(java.lang.Object)' on a null object reference
 
Solution
You don't have to use mysql 5.x. you should be able to use newer mysql versions with the latest 5.1 driver. Have you tried? Don't use 8.x driver

calloatti

Member
Licensed User
Probably remove ".jar" from the #AdditionalJar line

And also, maybe use InitializeAsync instead of Initialize2
 
Last edited:
Upvote 0

tanush62

Member
It doesn't matter whether you exclude the jar extension or not.

First step is to post the full error message with the stack trace and the relevant code.
My bad Erel. Not error, but "Log(LastException.Message)" in line 13 give me this message and i cold not connect
 
Upvote 0

tanush62

Member
Here is the full error message when I remove try - catch

Error:
Error occurred on line: 150 (Main)
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.
    at java.lang.reflect.Constructor.newInstance0(Native Method)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
    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:956)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:935)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:924)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:870)
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2311)
    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 java.lang.reflect.Constructor.newInstance0(Native Method)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
    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 java.sql.DriverManager.getConnection(DriverManager.java:580)
    at java.sql.DriverManager.getConnection(DriverManager.java:218)
    at anywheresoftware.b4j.objects.SQL.Initialize2(SQL.java:56)
    at com.kaf033.main._appset(main.java:842)
    at com.kaf033.main._activity_create(main.java:746)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:146)
    at com.kaf033.main.afterFirstLayout(main.java:105)
    at com.kaf033.main.access$000(main.java:17)
    at com.kaf033.main$WaitForLayout.run(main.java:83)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:224)
    at android.app.ActivityThread.main(ActivityThread.java:7590)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object java.util.Map.get(java.lang.Object)' on a null object reference
    at com.mysql.jdbc.ConnectionImpl.getServerCharset(ConnectionImpl.java:2983)
    at com.mysql.jdbc.MysqlIO.sendConnectionAttributes(MysqlIO.java:1873)
    at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1802)
    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)
    ... 29 more
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
You don't have to use mysql 5.x. you should be able to use newer mysql versions with the latest 5.1 driver. Have you tried? Don't use 8.x driver
 
Upvote 1
Solution

tanush62

Member
You don't have to use mysql 5.x. you should be able to use newer mysql versions with the latest 5.1 driver. Have you tried? Don't use 8.x driver
You ate telling me that too late :). After I uninstall Mysql 8.0.29 and install 5.1.34. But I will install it again. ?
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
Maybe adding the port after the address ? (check if it is 3308)

B4X:
mysql.Initialize2("com.mysql.jdbc.Driver", "jdbc:mysql://192.168.0.11:3308/information_schema", user, pass)
 
Upvote 0
Top