Android Question MYSQL SELECT works, but not INSERT

Kirk Grayson

Member
Licensed User
Greetings, been banging my head against the wall on this one. I'm using jRDC2 with B4J for my android, when I run my SELECT statement it works
SELECT:
Sub get_user (count As Int)
    Dim req As DBRequestManager = CreateRequest
    Dim cmd As DBCommand = CreateCommand("get_one_user", Array(count))
    Wait For (req.ExecuteQuery(cmd, 0, Null)) JobDone(j As HttpJob)
    If j.Success Then
        req.HandleJobAsync(j, "req")
        Wait For (req) req_Result(res As DBResult)
        'work with result
        req.PrintTable(res)
    Else
        Log("ERROR: " & j.ErrorMessage)
    End If
    j.Release
End Sub

But when I try my INSERT
INSERT fails:
Sub add_user(fullname As String)
    Dim cmd As DBCommand = CreateCommand("add_user", Array(fullname))
    Dim j As HttpJob = CreateRequest.ExecuteBatch(Array(cmd), Null)
    Wait For(j) JobDone(j As HttpJob)
    If j.Success Then
        Log("Inserted successfully!")
    End If
    j.Release
End Sub

The error I get in the log is
ResponseError. Reason: Server Error, Response:
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/>
<title>Error 500 org.eclipse.jetty.io.EofException: Closed</title>
</head>
<body><h2>HTTP ERROR 500 org.eclipse.jetty.io.EofException: Closed</h2>
<table>
<tr><th>URI:</th><td>/rdc</td></tr>
<tr><th>STATUS:</th><td>500</td></tr>
<tr><th>MESSAGE:</th><td>org.eclipse.jetty.io.EofException: Closed</td></tr>
<tr><th>SERVLET:</th><td>anywheresoftware.b4j.object.JServlet-50378a4</td></tr>
</table>
<hr/><a href="https://eclipse.org/jetty">Powered by Jetty:// 11.0.9</a><hr/>
</body>

(I took out the HTML tags, wasnt sure it would affect the post)

my config.properties SQL commands are
sql.get_one_user = SELECT full_name FROM UserTable WHERE count = ?;
sql.add_user = INSERT INTO UserTable (full_name) VALUES (?);

I'd appreciate any suggestions. Thanks.
 

josejad

Expert
Licensed User
Longtime User
INSERT INTO UserTable (full_name) VALUES (?);
Have you try to run the sql query directly in phpmyadmin to see if it's working?
For example:
B4X:
INSERT INTO UserTable (full_name) VALUES ('kirk');
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Another clue would be the log that is produced by the jRDC2 server. For initial setup, I usually just run jRDC2 from the IDE (often in Debug mode) and then use the log window to see what is going on server side.
 
Upvote 0

Kirk Grayson

Member
Licensed User
Another clue would be the log that is produced by the jRDC2 server. For initial setup, I usually just run jRDC2 from the IDE (often in Debug mode) and then use the log window to see what is going on server side.
I think you mean this log:

Command: query: getusers, took: 256ms, client=192.168.0.11
(MySQLSyntaxErrorException) com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'full_name VALUES ['Kirk']' at line 1
(EofException) org.eclipse.jetty.io.EofException: Closed
Command: , took: 4ms, client=192.168.0.11


I think you may have found the issue. I have missed this community.
I had a field that did not have a default value, I change that to null and it solved the issue.
Thank you Oliver, Aeric and Jose.
 
Upvote 0
Top