Android Question JdbcSQL / PostgreSQL Issue

RichardKirk

Member
Licensed User
Have taken the example JdbcSQL Example, made changes to access PostgreSQL as I do not run MySQL.
I built the animals table (just name and id). However, the program will not run at all.
(using B4A 9.3)

Changes Made to Main:
#AdditionalJar: postgresql-42.2.6.jre7

Changes made to Starter:
Sub Process_Globals
Public mysql As JdbcSQL
Private driver As String = "org.postgresql.Driver"
Private jdbcUrl As String = "jdbc:postgresql://192.168.1.128:5432/wxexamples"
Private Username As String = "postgres"
Private Password As String = "masterkey"
End Sub

In ListAnimals:
Dim sf As Object = mysql.ExecQueryAsync("mysql", "SELECT id, name FROM animals WHERE id < 10", Array(300))


The Log is very long, but the salient points to do with the connection seem to be as follows:
--------- beginning of crash
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
Service started in the background. Trying to start again in foreground mode.
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
main_activity_create (java line: 352)
android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14 SQLITE_CANTOPEN): Could not open database
at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:211)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:195)
at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:503)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:204)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:196)
at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:880)
at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:865)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:766)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:714)
at anywheresoftware.b4a.sql.SQL.Initialize(SQL.java:44)
at b4a.example.main._activity_create(main.java:352)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
at b4a.example.main.afterFirstLayout(main.java:104)
at b4a.example.main.access$000(main.java:17)
at b4a.example.main$WaitForLayout.run(main.java:82)
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)
I Make no reference to SQLite - where am I going wrong.
 

OliverA

Expert
Licensed User
** Activity (main) Create, isFirst = true **
main_activity_create (java line: 352)
android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14 SQLITE_CANTOPEN): Could not open database
You must have modified the example besides the information given in you initial post. According to this log, you are opening an SQLite database in Activity_Create, whereas in the example, it's just
B4X:
Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   Activity.LoadLayout("1")

End Sub
You could have also just posted the wrong logs.

Link:
https://www.b4x.com/android/forum/threads/jdbcsql-directly-connect-to-remote-databases.84016/
 

DonManfred

Expert
Licensed User
Public mysql As JdbcSQL
Private driver As String = "org.postgresql.Driver"
Private jdbcUrl As String = "jdbc:postgresql://192.168.1.128:5432/wxexamples"
Private Username As String = "postgres"
Private Password As String = "masterkey"
End Sub
Please use [CODE]code here...[/CODE] tags when posting code.



 

RichardKirk

Member
Licensed User
I have no idea what was going wrong. Did a complete reinstall of B4A, Libraries.
Downloaded JdbcSQL again, and now the example runs - still not connecting,
but the logs make a lot more sense!
Thank you for all your trouble!
 
Top