Android Question Need a Sample login screen app connecting to MySQL using RDC

Anser

Well-Known Member
Licensed User
Longtime User
Hi all,

I am new to B4A and this is my first thread in the forum. I am a newbie and very much new to Android app development. I am not even sure whether this is the right forum to ask this question. Its only few days since I started reading articles on the forum.

I read the article regarding the RDC and I have done a setup on my PC and it is working fine. So that part is clear.

I have been searching this forum for a sample app which does the following using RDC

  1. When I run my app it should bring up a Login window that contains 2 EditText controls to key in the Login username and password. A button to start the login verification process on a remote MySQL server.
  2. The username and password should be validated with records in a MySQL Table (I know that it is not a good habit to keep the username and password on table inside the database, but to start off, I will use this method initially). If its a valid username & password, then the app should take the user to another screen where he will have multiple menu to do other required jobs. If the user typed an invalid username and password, then the app should inform the user that is is a an invalid login and should remain in the Login screen itself.

The MySQL database will have a Table named 'users' with 2 columns 'usename' and 'password'

I don't know whether what I am asking is too much or not. I feel that I need an initial push from the experienced people in the group to get me started.

Any help will be appreaciated.

Thanks & Regards

Anser
 

Anser

Well-Known Member
Licensed User
Longtime User
Thank you Erel.

I was about to use the "LIKE %" in the same way as you suggested. I was waiting for a confirmation from your side, as I was not aware whether there is already some other solution to handle "LIKe %test%" in RDC.

Everything working fine here in RDC.

Regards
Anser
 
Upvote 0

Juan Marrero

Active Member
Licensed User
Longtime User
Erel, that way is not working for me. The error message is just: Error: Server Error. I tried sending %pdesc% and '%pdesc%' in my app and the same error is returned. This is the SQL query i used (this query is in config.properties file):
B4X:
SELECT Description, PartNumber, ProductID FROM Products WHERE Description LIKE ? ORDER BY Description ASC
This is the code in my app:
B4X:
Sub btnEnterProd_Click
   GetFilteredProductOnline("'%" & txtDescription.Text & "%'")
End Sub

Sub GetFilteredProductOnline(pdesc As String)
   Dim cmd As DBCommand
   cmd.Initialize
   cmd.Name = "GetFilteredProducts"
   cmd.Parameters = Array As Object(pdesc)
   reqManager.ExecuteQuery(cmd, 0, "GetFilteredProducts")
End Sub

Sub JobDone(Job As HttpJob)
   If Job.Success = False Then
     Msgbox("Error: " & Job.ErrorMessage, "")
    
     txtDescription.Text = ""
     txtIDSelected.Text = ""
     txtDescription.RequestFocus
   Else
     Try
       If Job.JobName = "DBRequest" Then
         Dim result As DBResult = reqManager.HandleJob(Job)
         If result.Tag = "GetFilteredProducts" Then 'query tag
         If result.Rows.Size > 0 Then
             For Each records() As Object In result.Rows
               lv.AddSingleLine(records(result.Columns.Get("Description")) & " : " & records(result.Columns.Get("PartNumber")) & " : " & records(result.Columns.Get("ProductID")))
               lv.RequestFocus
          Next
           Else
             If modMain.LANGUAGE = "Spanish" Then
               Msgbox("Producto No Encontrado", "")
             Else
               Msgbox("Product Not Found", "")
             End If
           End If
         End If
       End If
     Catch
       Msgbox(LastException.Message, "")
     End Try
   End If
   Job.Release
End Sub

Possibly there is something configured or coded wrong but I can't seem to find it. I will keep looking carefully but if anyone find something please tell.
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
So these do not work for you?

B4X:
SELECT Description, PartNumber, ProductID FROM Products WHERE Description LIKE'%" & pdesc & "%' ORDER BY Description ASC

B4X:
SELECT Description, PartNumber, ProductID FROM Products WHERE Description LIKE'%pdesc%' ORDER BY Description ASC
 
Upvote 0

Anser

Well-Known Member
Licensed User
Longtime User
It seems that your problem is here.
B4X:
GetFilteredProductOnline("'%" & txtDescription.Text & "%'")

Change it to
B4X:
GetFilteredProductOnline("%" & txtDescription.Text & "%")

Then your SQL entry in the config file should work fine.
B4X:
SELECT Description, PartNumber, ProductID FROM Products WHERE Description LIKE ? ORDER BY Description ASC

Regards
Anser
 
Upvote 0

Juan Marrero

Active Member
Licensed User
Longtime User
I want to apologize. The code works OK. My mistake was that the RDC was reading the wrong config.properties file. As soon as i copied the correct file to the RDC folder everything started working. My apologies.
 
Upvote 0
Top