T tanush62 Member Sep 26, 2022 #1 I'm trying to connect to mysql server on local nettwork. What I'm doing wrong? [CODE lang="b4x" title="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 [/CODE] I got the error: [CODE lang="b4x" title="Code"] java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object java.util.Map.get(java.lang.Object)' on a null object reference [/CODE]
I'm trying to connect to mysql server on local nettwork. What I'm doing wrong? [CODE lang="b4x" title="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 [/CODE] I got the error: [CODE lang="b4x" title="Code"] java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object java.util.Map.get(java.lang.Object)' on a null object reference [/CODE]
Solution OliverA Sep 28, 2022 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 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
C calloatti Member Licensed User Sep 26, 2022 #2 Probably remove ".jar" from the #AdditionalJar line And also, maybe use InitializeAsync instead of Initialize2 Last edited: Sep 26, 2022 Upvote 0
Probably remove ".jar" from the #AdditionalJar line And also, maybe use InitializeAsync instead of Initialize2
E edgar_ortiz Active Member Licensed User Longtime User Sep 27, 2022 #3 Check: https://www.b4x.com/android/forum/t...ation-of-rdc-remote-database-connector.61801/ Upvote 0
T tanush62 Member Sep 27, 2022 #4 calloatti said: Probably remove ".jar" from the #AdditionalJar line And also, maybe use InitializeAsync instead of Initialize2 Click to expand... Tried without jar, result the same. Upvote 0
calloatti said: Probably remove ".jar" from the #AdditionalJar line And also, maybe use InitializeAsync instead of Initialize2 Click to expand... Tried without jar, result the same.
T tanush62 Member Sep 27, 2022 #5 edgar_ortiz said: Check: https://www.b4x.com/android/forum/t...ation-of-rdc-remote-database-connector.61801/ Click to expand... This is solution if database is on web. Mine is on local network. Upvote 0
edgar_ortiz said: Check: https://www.b4x.com/android/forum/t...ation-of-rdc-remote-database-connector.61801/ Click to expand... This is solution if database is on web. Mine is on local network.
Erel B4X founder Staff member Licensed User Longtime User Sep 27, 2022 #6 tanush62 said: Tried without jar, result the same. Click to expand... 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. Upvote 0
tanush62 said: Tried without jar, result the same. Click to expand... 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.
T tanush62 Member Sep 27, 2022 #7 Erel said: 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. Click to expand... My bad Erel. Not error, but "Log(LastException.Message)" in line 13 give me this message and i cold not connect Upvote 0
Erel said: 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. Click to expand... My bad Erel. Not error, but "Log(LastException.Message)" in line 13 give me this message and i cold not connect
T tanush62 Member Sep 28, 2022 #8 Here is the full error message when I remove try - catch [CODE lang="b4x" title="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 [/CODE] Upvote 0
Here is the full error message when I remove try - catch [CODE lang="b4x" title="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 [/CODE]
OliverA Expert Licensed User Longtime User Sep 28, 2022 #9 You need to use the latest 5.1 JDBC driver. Why? See https://stackoverflow.com/a/50082287 Link to latest 5.1 version: https://downloads.mysql.com/archives/c-j/ Upvote 0
You need to use the latest 5.1 JDBC driver. Why? See https://stackoverflow.com/a/50082287 Link to latest 5.1 version: https://downloads.mysql.com/archives/c-j/
T tanush62 Member Sep 28, 2022 #10 OliverA said: You need to use the latest 5.1 JDBC driver. Why? See https://stackoverflow.com/a/50082287 Link to latest 5.1 version: https://downloads.mysql.com/archives/c-j/ Click to expand... I tried with jdbc 8.0.29 (my Mysql server is v. 8.0.29) it didn't work too. I gues I'll have to use mysql server 5.1.x to get it work. Any suggestions @Erel ? Last edited: Sep 28, 2022 Upvote 0
OliverA said: You need to use the latest 5.1 JDBC driver. Why? See https://stackoverflow.com/a/50082287 Link to latest 5.1 version: https://downloads.mysql.com/archives/c-j/ Click to expand... I tried with jdbc 8.0.29 (my Mysql server is v. 8.0.29) it didn't work too. I gues I'll have to use mysql server 5.1.x to get it work. Any suggestions @Erel ?
Erel B4X founder Staff member Licensed User Longtime User Sep 28, 2022 #11 tanush62 said: Any suggestions @Erel ? Click to expand... Use jRDC2 instead of connecting directly to the db. Upvote 0
tanush62 said: Any suggestions @Erel ? Click to expand... Use jRDC2 instead of connecting directly to the db.
OliverA Expert Licensed User Longtime User Sep 28, 2022 #12 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
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
T tanush62 Member Sep 28, 2022 #13 OliverA said: 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 Click to expand... 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
OliverA said: 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 Click to expand... 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. ?
marcick Well-Known Member Licensed User Longtime User Oct 3, 2022 #14 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
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)
T tanush62 Member Oct 3, 2022 #15 marcick said: 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) Click to expand... Problem solved. I changed JDBC connector to ver. 5.1.49 (latest as @OliverA suggested) and it is working. Upvote 0
marcick said: 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) Click to expand... Problem solved. I changed JDBC connector to ver. 5.1.49 (latest as @OliverA suggested) and it is working.