B4J Question [ABMaterial] Login page Sample with MySQL

Anser

Well-Known Member
Licensed User
Longtime User
Hi,

I am just testing ABMaterial to try and learn to develop a webapp. My knowledge level is zero in WebApp development

As described in the Get Started, I copied the Template Folder to my Project Folder and then renamed Template.b4j and Template.b4j.meta to my project names

I do not know what to me done next. As per the write up in the 'Get Started', I am supposed to modify the initialpage variable's value. For the time being I used
Private InitialPage As String = "ABMPageTemplate"

Can anyone point me to the right direction to get the below given points done.

As a beginner, I am trying to achieve the following

  • Point No 1
Whenever my Webapp is invoked, I want to take the user to a login page. I could get this done by changing ABMShared.NeedsAuthorization = True

What I need is that the username and password should be validated against a row in a table available on a remote MySQL server. Really do not know, where I should mention the connection details to access MySQL with the MySQL username and passwords and then to verify the user typed username and password with the data available in the users table. Once the connection to MySQL is established, will the connection remain open OR each time I make a query to MySQL, will I have to open the connection once again ?
Is it possible to use Connection Pool ?
OR
Is it better to use jRDC ?

OR in other words. My application will be using MySQL database from a remote server (Hopefully, my AbMaterial Webapp and database resided on the same server. So what is the kind of tools available for making database application using AbMaterial ?

  • Point no 2
While running the webapp, whenever I close the browser and if I try to access the website once again, then it is not taking me to the Login page, instead it is straight away going to my home page ie TemplatePage. For eg http://localhost:51042/TestWebApp. How can I ensure that whenever my user closes the webpage and then reopen it, it should ask for the Login credentials.


I do not even know whether the questions that I have raised here are stupid ones or not

Thanks in advance
 
Last edited:

Anser

Well-Known Member
Licensed User
Longtime User
Friends,

I think I found the answer

DBM Module is the answer for connecting your WebApp with a database

In you Main Module Include
#AdditionalJar: mysql-connector-java-5.1.44-bin

And in
B4X:
Sub AppStart (Args() As String)
    ' the user needs to login
    ABMShared.NeedsAuthorization = True

    ' Build the Theme
    ABMShared.BuildTheme("mytheme")

    ' Connect to MySql Server
    DBM.InitializeMySQL("yoururl", "yourlogin", "yourpassword", 100)

Now my doubt is should I disconnect from the MySQL server while I quit the app ? Or else will there be resource leakage ?

I found the Following sub in DBM
B4X:
Sub CloseSQL(mySQL As SQL)
    If UsePool Then
        mySQL.Close
    End If  
End Sub

So which is the right place in the Code to make a call to this Sub CloseSql ?
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
I always close it immidiate after I did my database manipulations:

So in main:
B4X:
DBM.InitializeMySQL("....

If I need to do a database manipulation (SELECT, INSERT, ...)
B4X:
Dim SQL As SQL = DBM.GetSQL ' get a connection from the pool

' do all the queries needed

DBM.CloseSQL(SQL) ' release the connection to the pool so it is available for something else
 
Upvote 0
Top