B4J Question Passing a list parameter in config.properties

Setlodi

Active Member
Hi there

I hope someone can help me with the challenge of passing a list in config.properties file.
config.properties string:
sql.mark_orders_pushed_to_dashboard=UPDATE orderSummary_Table SET Pushed_To_Dashboard = 1 WHERE Order_ID IN (#)

My b4j code:
B4X:
Public Sub Echo_Test
Dim orderIDs As List
orderIDs.Initialize
orderIDs.AddAll(Array As String("ORD_SHOP001_1463", "ORD_SHOP002_9851", "ORD_SHOP003_5781"))

    Dim params(orderIDs.Size) As Object
    For i = 0 To orderIDs.Size - 1
        params(i) = orderIDs.Get(i)
    Next

    Dim cmd As DBCommand = CreateCommand("mark_orders_pushed_to_dashboard", Array As Object(params))

Dim req As DBRequestManager
req.Initialize(Me, rdcLink)
req.ExecuteCommand(cmd, Null)

Wait For JobDone(j As HttpJob)
If j.Success Then
    Log("✅ Update successful")
Else
    Log("❌ Update failed: " & j.ErrorMessage)
End If
j.Release
End Sub

I'm getting this error:
B4X:
❌ Update failed: <html>
<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-4e08711f</td></tr>
</table>
<hr/><a href="https://eclipse.org/jetty">Powered by Jetty:// 11.0.9</a><hr/>
</body>
</html>

Error from nohup in VPS
B4X:
(SQLException) java.sql.SQLException: No value specified for parameter 2
(EofException) org.eclipse.jetty.io.EofException: Closed
Command: , took: 10ms, client=105.209.231.27

When I pass 3 objects it works:
B4X:
Dim cmd As DBCommand = CreateCommand("mark_orders_pushed_to_dashboard", Array As Object( _
  orderIDs.Get(0), orderIDs.Get(1), orderIDs.Get(2)))

Thank you in advance
 

aeric

Expert
Licensed User
Longtime User
params is already an array. You don't need to wrap it inside a new array.
B4X:
Dim cmd As DBCommand = CreateCommand("mark_orders_pushed_to_dashboard", params)
 
Upvote 0

Setlodi

Active Member
B4J Error:
B4X:
❌ Update failed: <html>
<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-4e08711f</td></tr>
</table>
<hr/><a href="https://eclipse.org/jetty">Powered by Jetty:// 11.0.9</a><hr/>
</body>
</html>

Server Error:
B4X:
(SQLException) java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
(EofException) org.eclipse.jetty.io.EofException: Closed
Command: , took: 1895ms, client=105.209.231.27
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Also change:
B4X:
req.ExecuteCommand(cmd, Null)
to
B4X:
Dim j As HttpJob = req.ExecuteCommand(cmd, Null)


B4X:
Wait For JobDone(j As HttpJob)
to
B4X:
Wait For(j) JobDone(j As HttpJob)


or
B4X:
'Dim req As DBRequestManager
'req.Initialize(Me, rdcLink)
'req.ExecuteCommand(cmd, Null)
'Wait For JobDone(j As HttpJob)
Dim j As HttpJob = CreateRequest.ExecuteCommand(cmd, Null)
Wait For(j) JobDone(j As HttpJob)
 
Upvote 0

Setlodi

Active Member
Thank you for your help and your time aeric.
this code:
B4X:
Public Sub Echo_Test
    Dim orderIDs As List
    orderIDs.Initialize
    orderIDs.AddAll(Array As String("ORD_SHOP001_1463", "ORD_SHOP002_9851", "ORD_SHOP003_5781"))

    Dim params(orderIDs.Size) As Object
    For i = 0 To orderIDs.Size - 1
        params(i) = orderIDs.Get(i)
    Next

    Dim cmd As DBCommand = CreateCommand("mark_orders_pushed_to_dashboard", params)

    Dim j As HttpJob = CreateRequest.ExecuteCommand(cmd, Null)
    Wait For(j) JobDone(j As HttpJob)
    If j.Success Then
        Log("✅ Update successful")
    Else
        Log("❌ Update failed: " & j.ErrorMessage)
    End If
    j.Release
End Sub

config.properties:
sql.mark_orders_pushed_to_dashboard=UPDATE orderSummary_Table SET Pushed_To_Dashboard = 1 WHERE Order_ID IN (#)

is till giving errors:

B4J error:
❌ Update failed: <html>
<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-4e08711f</td></tr>
</table>
<hr/><a href="https://eclipse.org/jetty">Powered by Jetty:// 11.0.9</a><hr/>
</body>
</html>

Server error:
(SQLException) java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
(EofException) org.eclipse.jetty.io.EofException: Closed
Command: , took: 31ms, client=105.209.231.27
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
sql.mark_orders_pushed_to_dashboard=UPDATE orderSummary_Table SET Pushed_To_Dashboard = 1 WHERE Order_ID IN (#)
Why you use # character?
It can cause the command ended as comment.
AFAIK, you should only use ? character as placeholder.
Try log the value of the command.

I think it should be
B4X:
sql.mark_orders_pushed_to_dashboard=UPDATE orderSummary_Table SET Pushed_To_Dashboard = 1 WHERE Order_ID IN (?, ?, ?)
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
You can also directly just use array without adding the values to a list.
B4X:
'Dim orderIDs As List
'orderIDs.Initialize
'orderIDs.AddAll(Array As String("ORD_SHOP001_1463", "ORD_SHOP002_9851", "ORD_SHOP003_5781"))
'Dim params(orderIDs.Size) As Object
'For i = 0 To orderIDs.Size - 1
'    params(i) = orderIDs.Get(i)
'Next
'Dim cmd As DBCommand = CreateCommand("mark_orders_pushed_to_dashboard", params)
Dim cmd As DBCommand = CreateCommand("mark_orders_pushed_to_dashboard", Array As String("ORD_SHOP001_1463", "ORD_SHOP002_9851", "ORD_SHOP003_5781"))
 
Upvote 0

Setlodi

Active Member
aeric, this is just for testing, the list will be populated from other functions...
when i hardcode the values it works, but i want to use a list

this is my latest code:

B4J code:
Public Sub Echo_Test
    Dim orderIDs As List
    orderIDs.Initialize
    orderIDs.AddAll(Array As String("ORD_SHOP001_1463", "ORD_SHOP002_9851", "ORD_SHOP003_5781"))

    Dim params(orderIDs.Size) As Object
    For i = 0 To orderIDs.Size - 1
        params(i) = orderIDs.Get(i)
    Next
  
    Log("✅ orderIDs = " & orderIDs)
    Log("✅ params = " & Array(params))

    Dim cmd As DBCommand = CreateCommand("mark_orders_pushed_to_dashboard", params)

    Dim j As HttpJob = CreateRequest.ExecuteCommand(cmd, Null)
    Wait For(j) JobDone(j As HttpJob)
    If j.Success Then
        Log("✅ Update successful")
    Else
        Log("❌ Update failed: " & j.ErrorMessage)
    End If
    j.Release
End Sub

it is failing and the logs show me:
B4X:
✅ orderIDs = (ArrayList) [ORD_SHOP001_1463, ORD_SHOP002_9851, ORD_SHOP003_5781]
✅ params = [Ljava.lang.Object;@28c0c441

here's my revised config.properties
config.properties:
sql.mark_orders_pushed_to_dashboard=UPDATE orderSummary_Table SET Pushed_To_Dashboard = 1 WHERE Order_ID IN (?)

i also tried:
B4X:
Dim cmd As DBCommand = CreateCommand("mark_orders_pushed_to_dashboard", Array As Object(orderIDs))
it gives no errors but in my DB there are no changes, i.e. Pushed_To_Dashboard = 0 instead of Pushed_To_Dashboard = 1
 
Upvote 0

Setlodi

Active Member
Thank you Erel for your response. I have tried:
B4J code:
Dim cmd As DBCommand = CreateCommand("mark_orders_pushed_to_dashboard", params)

It's failing:
B4J error:
❌ Update failed: <html>
<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-302552ec</td></tr>
</table>
<hr/><a href="https://eclipse.org/jetty">Powered by Jetty:// 11.0.9</a><hr/>
</body>
</html>
Server error:
(SQLException) java.sql.SQLException: Parameter index out of range (2 > number of parameters, which is 1).
(EofException) org.eclipse.jetty.io.EofException: Closed
Command: , took: 7ms, client=105.209.231.27

and this
B4X:
Log("cmd = " & cmd)
shows
cmd = [IsInitialized=true, Name=mark_orders_pushed_to_dashboard, Parameters=[Ljava.lang.Object;@7034fb24
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
You still have only 1 placeholder.
If you want to make a dynamic query, I think you should count the number of params then amend the query.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…