B4J Question MySQL inserting a record from textFields [Solved]

Peter Lewis

Active Member
Licensed User
Longtime User
Hi All

Please can someone point me in the right direction. I know i have done this before but many months ago.

I have a registration page with textfields which i want to insert into my remote Mysql Database. I have searched there forums but could not find any answers.

The test fields I have as Private in the Code Module

I also have another Code Module that does all my Database code

I have tested a single line code that works and it does insert the data that I specify in that line, but for the life of me I cannot get the data from the form into the database. I even took the database routine into the form Code Module and still did not work. I tried to pass the data though the function and it said i was missing a ")" and when I put an extra one in it came back to me as too many ) .

I normally like to try and solve these items myself but it is now getting frustrating and short of me going to watch all the tutorial videos I thought I would ask.

Here is the code that works and I want to have the variables that are specified first in that line




write to mysql:
Sub UserRemoteAdd
   



    Private dtaCellular As TextField
    Private dtaCity As TextField
    Private dtaCountry As TextField
    Private dtaDOB As DatePicker
    Private dtaEmail As TextField
    Private dtaLastName As TextField
    Private dtaName As TextField
    Private dtaPassword As TextField
    Private dtaPostCode As TextField
    Private dtaProvence As TextField
    Private dtaUsername As TextField



   
    If Sql2.IsInitialized = False Then    'in case the connection closes
        Sql2.Initialize2("com.mysql.jdbc.Driver", "jdbc:mysql://112.215.252.76:3306/ted_quiz", "ted_quizuser", "pass)")
        Log("init database")
    End If
   

    Sql2.ExecNonQuery2("INSERT INTO User_db VALUES (?, ?, ?, ?,?,?,?,?,?,?,?,?,?)", Array As Object(Null,"sope ","","","",786868,"","1965-03-17","","","",2,1))







End Sub

Thank you in Advance
 
Last edited:

Peter Lewis

Active Member
Licensed User
Longtime User
I just tried one of the fields

B4X:
Sql2.ExecNonQuery2("INSERT INTO User_db VALUES (?, ?, ?, ?,?,?,?,?,?,?,?,?,?)", Array As Object(Null,"sope ","","","",dtaCellular,"","1965-03-17","","","",2,1))

and the error was

java.sql.SQLException: Invalid argument value: java.io.NotSerializableException
 
Upvote 0

Peter Lewis

Active Member
Licensed User
Longtime User
Are you sure this part is correct?
yes i am as if I run it and use the code line I showed first. It does insert the data into the database correctly. But now i need the data to come from the text entry fields on a form and this is where I am having the problem

I did change the IP , username and password to post as I did not want anyone to hack it

Thank you
 
Upvote 0

Peter Lewis

Active Member
Licensed User
Longtime User
Have you tried?
B4X:
dtaCellular.Text
No, let me try that. Like I mentioned I have not done any programming for a while and i would watch all the tutorials again but here in South Africa our 2 international lines are broken and the Internet is VERY slow. Expected to be repaired by the 4th next month. SAT3 and WACS
 
Upvote 0

Peter Lewis

Active Member
Licensed User
Longtime User
Have you tried?
B4X:
dtaCellular.Text
Hi

I went o all the fields and they worked correctly except the Date one. Do i have to do a string convert first on that so it is also a .text

Thank you
Pls, could you edit the subject thread adding [SOLVED]?
Already did that , thank you. Just the Date field I have a question on.
 
Upvote 0
Top