bfw
Member
Hi @ all,
I have two methods implement to connect to a MariaDB
I call this like
When I run my program, the following exception is thrown
Knows anybody what's wrong?
I have two methods implement to connect to a MariaDB
Code:
Sub ConnectToMariaDB(jdbcURL As String, username As String, password As String) As JavaObject
Dim driver As JavaObject
driver.InitializeNewInstance("org.mariadb.jdbc.Driver", Null)
Dim connection As JavaObject = driver.RunMethod("connect", Array(jdbcURL, CreateCredentials(username, password)))
Return connection
End Sub
Sub CreateCredentials(username As String, password As String) As JavaObject
Dim properties As JavaObject
properties.InitializeNewInstance("java.util.Properties", Null)
properties.RunMethod("setProperty", Array("user", username))
properties.RunMethod("setProperty", Array("password", password))
Return properties
End Sub
I call this like
Code:
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
...
Try
Dim jdbcURL As String = "jdbc:mariadb://localhost/bfw"
sqlConnection = ConnectToMariaDB(jdbcURL, "bfw", "bfw")
Catch
Log(LastException)
End Try
End Sub
When I run my program, the following exception is thrown
B4X:
Error occurred on line: 115 (B4XMainPage)
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
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:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
at b4a.program.b4xmainpage._connecttomariadb(b4xmainpage.java:101)
at b4a.program.b4xmainpage._b4xpage_created(b4xmainpage.java:86)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:318)
at anywheresoftware.b4a.debug.Debug.CallSubNew2(Debug.java:285)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.keywords.Common.CallSubDebug2(Common.java:1087)
at b4a.program.b4xpagesmanager._createpageifneeded(b4xpagesmanager.java:1068)
at b4a.program.b4xpagesmanager._showpage(b4xpagesmanager.java:425)
at b4a.program.b4xpagesmanager._addpage(b4xpagesmanager.java:245)
at b4a.program.b4xpagesmanager._addpageandcreate(b4xpagesmanager.java:259)
at b4a.program.b4xpagesmanager._initialize(b4xpagesmanager.java:165)
at b4a.program.main._activity_create(main.java:415)
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:157)
at b4a.program.main.afterFirstLayout(main.java:105)
at b4a.program.main.access$000(main.java:17)
at b4a.program.main$WaitForLayout.run(main.java:83)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.sql.SQLNonTransientConnectionException: Socket fail to connect to localhost. failed to connect to localhost/127.0.0.1 (port 3306) from /127.0.0.1 (port 32864) after 30000ms: isConnected failed: ECONNREFUSED (Connection refused)
at org.mariadb.jdbc.client.impl.ConnectionHelper.connectSocket(ConnectionHelper.java:131)
at org.mariadb.jdbc.client.impl.StandardClient.<init>(StandardClient.java:127)
at org.mariadb.jdbc.Driver$$ExternalSyntheticLambda1.apply(D8$$SyntheticClass:0)
at org.mariadb.jdbc.Driver.connect(Driver.java:73)
at org.mariadb.jdbc.Driver.connect(Driver.java:102)
at org.mariadb.jdbc.Driver.connect(Driver.java:27)
... 38 more
Caused by: java.net.ConnectException: failed to connect to localhost/127.0.0.1 (port 3306) from /127.0.0.1 (port 32864) after 30000ms: isConnected failed: ECONNREFUSED (Connection refused)
at libcore.io.IoBridge.isConnected(IoBridge.java:278)
at libcore.io.IoBridge.connectErrno(IoBridge.java:187)
at libcore.io.IoBridge.connect(IoBridge.java:129)
at java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:137)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:390)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:230)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:212)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:436)
at java.net.Socket.connect(Socket.java:621)
at org.mariadb.jdbc.client.impl.ConnectionHelper.connectSocket(ConnectionHelper.java:118)
... 43 more
Caused by: android.system.ErrnoException: isConnected failed: ECONNREFUSED (Connection refused)
at libcore.io
Knows anybody what's wrong?