B4J Question SQLException SQL error or missing Database! Help Please

sizap

New Member
Helloy B4J folks,
i am trying to send Datas to my webserver and put them there into a SQL database named : SensorDatas.
Everything works but when my Handler trys to put the datas into the SQL database i receive this Exception.

B4X:
java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (near "17": syntax error)

I think that i understand what it means, but i don´t know how i can solve this issue.

Thats my Handler Code:

B4X:
Sub Handle(req As ServletRequest, resp As ServletResponse)
    Dim data As sensorDatas = Main.ReadObject(req.InputStream)
    Dim m As Map
    m.Initialize
    m.Put("Datas",data.datas)
    m.Put("Date", data.date )
    DBUtils.InsertValues(Main.SQL1, "SDatas", m)
    Log("Datas added succesfully.")
End Sub


And here the Subroutine InsertValues:

B4X:
Public Sub InsertValues (SQL As SQL, TableName As String, Values As Map)
    Dim sb As StringBuilder
    sb.Initialize
    sb.Append("INSERT INTO " & TableName & "(" & Values.GetKeyAt(0) & ", " & Values.GetKeyAt(1) & _
    ") VALUES (" & Values.GetValueAt(0) & ", " & Values.GetValueAt(1) & ")")
    Log(sb.ToString)
    SQL.ExecNonQuery(sb.ToString)
End Sub

The issue happend at the execute of the query.
I have no experience with SQL and Server, cause of that please be patient with me :)
And many thanks for youre help.
 

Daestrum

Expert
Licensed User
Longtime User
Are you trying to put string values into the database?
If you are, you will need to put a single quote before and after the value.
ie, values(one,two,three) need to be changed to values('one','two','three')
 
Upvote 0
Top