B4J Question Bit.io and B4J

AndrewF

Member
Licensed User
Longtime User
Hi,

I am having trouble connecting to bit,io online postgress db.
There error is "java.sql.SQLException: No suitable driver found for postgresql://xxxxxxxx but I think this maybe because SSL is not in the connection statement.
Can anyone help?


B4X:
Sub Class_Globals

    Private Root As B4XView

    Private xui As XUI

    Private SQL As SQL

  

    #Region Database Location

    Private DBLocation As String = "postgresql://connection from bit io"

    Private DBUsername As String = "bit io user"

    Private DBPassword As String = "bit io pass"

  

#End Region

End Sub



Public Sub Initialize

'    B4XPages.GetManager.LogEvents = True

End Sub



'This event will be called once, before the page becomes visible.

Private Sub B4XPage_Created (Root1 As B4XView)

    Root = Root1

    Root.LoadLayout("MainPage")

End Sub



'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.



Private Sub Button1_Click



    LogError("----------BIT IO (PostgreSQL) ----------")

    SQL.InitializeAsync("PostgreSQL", "org.postgresql.Driver", DBLocation, DBUsername, DBPassword)

    SQL.Close

End Sub
 

teddybear

Well-Known Member
Licensed User
Hi,

I am having trouble connecting to bit,io online postgress db.
There error is "java.sql.SQLException: No suitable driver found for postgresql://xxxxxxxx but I think this maybe because SSL is not in the connection statement.
Can anyone help?


B4X:
Sub Class_Globals

    Private Root As B4XView

    Private xui As XUI

    Private SQL As SQL

 

    #Region Database Location

    Private DBLocation As String = "postgresql://connection from bit io"

    Private DBUsername As String = "bit io user"

    Private DBPassword As String = "bit io pass"


#End Region

End Sub


End Sub

Maybe you used a wrong password, the password is not your bit.io password.
See Guides
  • The Password is not your bit.io password: this password is for accessing your database via a tool with a PostgreSQL connection or via the bit.io API. When connecting to a bit.io database and entering your database credentials, this password, and not your bit.io login password, will go in that connection's "password" field.
 
Upvote 0

AndrewF

Member
Licensed User
Longtime User
Thanks, I am now trying to access my bit.io using the rest api as I couldn't get the above to work, but having issues converting my php into okhttputils2.

The following http retrieves the correct information:
HTTP:
POST /v2beta/query HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer <APIKEY>
Host: api.bit.io
Content-Length: 89

{"query_string":"SELECT * FROM \"Companies\";","database_name":"<DBNAME>"}

However, I am struggling converting this into using okhttputils2. So far I have
B4X:
Dim j As HttpJob
    j.Initialize("job name", Me)
    j.PostString("https://api.bit.io/v2beta/query",$"{"query_string":"SELECT * FROM \"Companies\";","database_name":"<DBName>"}"$)
    j.GetRequest.SetHeader("Authorization","Bearer <APIKEY>")
    j.GetRequest.SetHeader("Accept","application/json")
    j.GetRequest.SetHeader("Content-Type","application/json")
    j.GetRequest.SetHeader("Host","api.bit.io")
    

    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        Log(j.GetString)
    End If
    j.Release

However this gives me the error, ResponseError. Reason: , Response: {"detail":[{"loc":["body"],"msg":"value is not a valid dict","type":"type_error.dict"}]} where as in the Https simulator it is working. I know I am getting through to the service ok and being authorised successfully in B4J as before the authorization header was added I was getting the response unauthorised.
 
Upvote 0
Top