Android Question How access the H2 database?

Thank you for your reply.
It embedded mode not server mode database.
It is in local,not remote database.
 
Upvote 0
I am first touch H2 databse.
I want connect to H2 database and read data from a table, only!
Does anybody have experience can give me a simple example.(with B4j or Java)
Thank you!
 
Upvote 0
I has found a way to connect H2 database with B4j, Share with everyone.

Code: Copy
#Region  Project Attributes
  #MainFormWidth: 600
  #MainFormHeight: 400
  #AdditionalJar: h2-1.3.176.jar
#End Region

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private sql2 As SQL
    Private rs As ResultSet
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.Show
    sql2.Initialize("org.h2.Driver", "jdbc:h2:file:C:\TEST\MyH2db;IFEXISTS=TRUE;MODE=PostgreSQL;USER=sa")
    rs= sql2.ExecQuery("SELECT * FROM CUSTOMER")
    Do While RS.NextRow
       Log(rs.GetString("CUS_ID") & "," & rs.GetString("CUS_NAME"))
    Loop
    rs.Close
End Sub
 
Upvote 0
My first B4j programe (above #11 reply: only change Log(....) to File.WriteString( File.DirApp, "out.txt",
rs.GetString("CUS_ID") & "," & rs.GetString("CUS_NAME")
) ) compile into .jar success. This JAR on my PC can execute.
But copy to another PC (has install Java Runtime &
h2-1.3.176.jar & jSQL.jar
) is fail(out.txt not created).

How can run this JAR on another PC? There anything missing is not installed yet. Thank you!
 
Upvote 0
Do you have #MergeLibraries: True in #Region Project Attributes? Try running the app from the command line with java -jar MyJar.jar to see what the error messages are.
 
Upvote 0
I found, may be is folder permissions question.
My program copy to c: root, it can't execute.
But copy to c:\temp it can be execute.??
 
Upvote 0
And the correct forum is NOT the b4a forum. You should have used the b4j forum.
 
Upvote 0
Back
Top