Android Question jrdc2: ZipException incorrect header check

josejad

Expert
Licensed User
Longtime User
Hi:

I'm testing jrdc2 and I'm having next issue

My config.properties
B4X:
#DATABASE CONFIGURATION
DriverClass=com.mysql.jdbc.Driver
JdbcUrl=jdbc:mysql://localhost/semi?characterEncoding=utf8
User=root
Password=*****
#Java server port
ServerPort=17178
.
.
.
sql.login=SELECT * FROM usuarios WHERE usuario=? AND password=md5(?)

My jrdc.b4j
B4X:
'change based on the jdbc jar file
#AdditionalJar: mysql-connector-java-5.1.44-bin
'#AdditionalJar: postgresql-9.4.1207
...
Sub AppStart (Args() As String)
    srvr.Initialize("")
    ...
    srvr.AddHandler("/semi", "TestHandler", False)
    ...
End Sub

If I test in chrome: http://localhost:17178/semi I get a successful connection.

My b4a project:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("login")
    reqManager.Initialize(Me, "http://192.168.1.60:17178/semi") 'my local computer with the b4j project running
End Sub

Sub BtLogin_Click
    Dim cmd As DBCommand
    cmd.Initialize
    cmd.Name = "login"
    reqManager.ExecuteQuery(cmd, 0, Null)
End Sub

Sub ReqManager_Result(result As DBResult)
    Dim Record() As Object
    Record = result.Rows.Get(0) ' The First Record,

    ToastMessageShow( Record(result.Columns.Get("usuario")) , False )

    'ToastMessageShow( Record(result.Columns.Get("name")) , False )
End Sub

When I run the b4a project and press BtLogin I get the error:
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
Error reading response: (ZipException) java.util.zip.ZipException: incorrect header check

I've checked the forum, I've found a similar thread and I've tried the solutions: update the SDK files, and checked I'm using latest versions of jrdc2 and DBRequestManager.

Thanks in advance¡
 

OliverA

Expert
Licensed User
Longtime User
Your query is expecting two parameters, yet your cmd object has none set. The jRDC2 server is a little unforgiving with errors (check server side logs). I'm pretty sure, as is, this will throw an SQLException error on the server. You may try my modded jRDC2 server (https://www.b4x.com/android/forum/threads/modded-jrdc2-w-sqlite-support-and-more.85578/) and see how it responds, what it returns with your "broken" request. If you do use the modded version, just make sure you change the configuration.properties file to your needs.

Update: I'm not advocating the use of the modded jRDC2. It is a little bit more forgiving with user errors (at least the ones I ran into - I'm sorta good at that - the user errors part) and without the original jRDC2 there would be no modded one.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
You are calling the TestHandler instead of the correct handler (RDCHandler).
Sometimes I should really wait and let @Erel give the correct answer (or I just need to pay more attention).
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
Thanks you both¡¡
Those were the errors.
I will give a try to the modded class when I have a little more experience :). Or maybe I test it to see if the error messages are more clear to me :)
If I use the parameters in this way: cmd.Parameters = Array As Object("username", "password") it works¡¡ (if username and password exist in the data base, if no, B4A-Bridge get restarted¡¡

But if I use:
B4X:
cmd.Parameters = Array As Object(ETUsuario.Text, ETPassword.Text) 'I've tried Array As String too

I get an error in line
B4X:
Record = result.Rows.Get(0) ' The First Record,

Error occurred on line: 83 (Main)
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.get(ArrayList.java:411)
at anywheresoftware.b4a.objects.collections.List.Get(List.java:117)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at anywheresoftware.b4a.BA$2.run(BA.java:360)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
If the SQL query returns nothing (no result), then result.rows.size = 0. Since you have no records returned, but are accessing them (via results.Rows.Get(0)), you are getting an IndexOutOfBoundsException. To avoid this, make sure you check and see if any rows have been returned (in your case, result.rows.size > 0) before accessing the rows ->

B4X:
If result.Rows.Size > 0 Then
   Record = result.Rows.Get(0)
Else
  ' There was no result for your query/a match did not exist
  ' Do whatever needs to be done for this case here
End If

or something like that.
 
Upvote 0
Top