B4J Question [SOLVED] [WebApp] Web Apps Overview, problems running it

j_o_h_n

Active Member
Licensed User
I managed to finally get the problems I was having sorted after trial and error, always have to learn the hard way!
I'll leave this question here in case some poor unfortunate has one or more of the same issues


Hi
I am unable to the this sample project from this tutorial to run without error.

The information provided on this recent thread helped get me over a lot of the hurdles but I am still stuck

Initially when you open this project you are advised that are missing several additional libraries

Erel and agraham point you to these if you search the forum:


Then after adding these to the additional files folder when you go to compile again you get a message that the jxl.jar file is missing from the internal libraries folder.

Aeric (referencing a post by Erel) tells you how to sort this issue:
- Download jexcel library: A Java library for reading/writing Excel - Browse /jexcelapi/2.6.12 at SourceForge.net (jexcelapi_2_6_12.zip).
- Open the zip file and copy jxl.jar to the (additional) libraries folder.

After that when you go to compile you'll almost definitely run into a problem with the line

B4X:
#AdditionalJar: mysql-connector-java-X.Y.Z-bin

This link in the forum points you in the right direction. You need to add the jar to the additional libraries folder and alter the x, y and z on the line above in the source to the values
in the name of the jar file.

After you fix that the project compiles but on running you discover that settings.txt file is missing from the application folder and
is needed to populate the Public settings map variable in App.Start.
This variable is referenced several times in the source so it is possible to learn from that the names of the keys in the file that
you should create.
So I created a text file settings.txt in the Objects folder containing the following text

Port : 8888
JdbcUrl: "jdbc:mysql://localhost:3307/test?characterEncoding=utf8"
DriverClass: "com.mysql.jdbc.Driver"
DBUser: "root"
DBPassword: "usbw"

I got all the parameters from another sample program serverhelloworld iirc, that's working fine locally and has this line in it
B4X:
pool.Initialize("com.mysql.jdbc.Driver", "jdbc:mysql://localhost:3307/test?characterEncoding=utf8", "root", "usbw")

When I then run the program it fails on the line below in Sub CreateUserTableIfNeeded in the DB module

B4X:
Dim sql1 As SQL = pool.GetConnection

The log gives the following error message:

WARNING: Could not load driverClass "com.mysql.jdbc.Driver"
java.lang.ClassNotFoundException: "com.mysql.jdbc.Driver"


Since I know that those settings work in the other program I'm a bit at a loss to know where to go from there.
Any help gratefully received!


EDIT 1
Actually replacing the commented out line with the one after it allows the program to run!
Beats me why though.

B4X:
Dim JdbcUrl As String = Main.settings.Get("JdbcUrl")
    Dim driverClass As String = Main.settings.Get("DriverClass")
    Dim dbuser As String = Main.settings.Get("DBUser")
    Dim dbpassword As String = Main.settings.Get("DBPassword")
    'pool.Initialize(driverClass, JdbcUrl, dbuser, dbpassword)
    pool.Initialize("com.mysql.jdbc.Driver", "jdbc:mysql://localhost:3307/test?characterEncoding=utf8", "root", "usbw")


EDIT 2
I discovered that the problem was the double quotes I had in the settings file I created, the format should have been
Port : 8888
JdbcUrl: jdbc:mysql://localhost:3307/test?characterEncoding=utf8
DriverClass: com.mysql.jdbc.Driver
DBUser: root
DBPassword: usbw

Then this line works fine
B4X:
pool.Initialize(driverClass, JdbcUrl, dbuser, dbpassword)
 
Last edited:

aeric

Expert
Licensed User
Longtime User
My advice is to follow a tutorial one line by one line patiently and don't get too excited so early.

Every word is very important (sometime, it doesn't look so obvious). Take note on the dependencies of other libraries. Try the search box to search for them.

Read the tutorial again for 2nd and 3rd time to understand. If there is a video attached, try to pause it after every 5 seconds or you want to rewind it. This happened to me when learning new concepts. My brain can only take 5 seconds of memory (pause a moment to write them into my brain cells). Don't modify the sample project so much. It may be useful to add Log() and some breakpoints in between and click Step In (F8) to read the value changes in log window. Sometimes, I can't visualize how the program is executing.

Usually, I will read up the entire thread until the last post. If there are links, I will click on them and open up new tabs. You will find that there are many examples with same prefix, e.g. [WebApp].
 
Upvote 0
Top