Android Question RDC / SQL Server java.sql.SQLException

Declan

Well-Known Member
Licensed User
Longtime User
I am attempting to query a SQL Server table with RDC.
I get this error:
B4X:
java.sql.SQLException: Conversion failed when converting date and/or time from character string.
Error: Server Error

My Config file on the server is:
B4X:
#SQL Server
DriverClass=net.sourceforge.jtds.jdbc.Driver
JdbcUrl=jdbc:jtds:sqlserver://197.xxx.xxx.xxx:1440/sectorstores
User=xxxxxx
Password=xxxxxx
ServerPort=17170
#If Debug is true then this file will be reloaded on every query.
#This is useful if you need to modify the queries.
Debug=true

#commands
sql.get_dates=SELECT DISTINCT [Sale Date] FROM SalesEndUser
sql.sales_end_user=SELECT * FROM SalesEndUser WHERE [Sale Date] BETWEEN ? AND ?

Where the first "?" is the StartDate and the second "?" is the EndDate

My Sub that calls this query is:
B4X:
Sub GetSales(Name As String)
    Dim cmd As DBCommand
    cmd.Initialize
    cmd.Name = "sales_end_user"
    cmd.Parameters = Array As Object(Name,StartDate,EndDate)
        Msgbox(StartDate,"StartDate")
        Msgbox(EndDate,"EndDate")
        Msgbox(cmd,"CMD")
    reqManager.ExecuteQuery(cmd, 0, "GetSales")
End Sub
Both variables; StartDate and EndDate are Global variables.
The MsgBox(s) are only for "debug" to make sure I have the correct data from the variables.
 

Anser

Well-Known Member
Licensed User
Longtime User
Where the first "?" is the StartDate and the second "?" is the EndDate

B4X:
sql.sales_end_user=SELECT * FROM SalesEndUser WHERE [Sale Date] BETWEEN ? AND ?
As per your SQL statement, your SQL query expects ONLY 2 parameters , but you are sending 3 parameters.

cmd.Parameters = ArrayAs Object(Name,StartDate,EndDate)

First parameter that you are sending is name, 2nd parameter is StartDate, 3rd parameter is EndDate


Regards
Anser
 
Upvote 0

erasmusackon

Member
Licensed User
Longtime User
Please help.

#SQL Server
DriverClass=net.sourceforge.jtds.jdbc.Driver
JdbcUrl=jdbc:jtds:sqlserver://XXX.XXX.X.XX:1433/smart_microfinance
User=*****
Password=******
ServerPort=1433
#If Debug is true then this file will be reloaded on every query.
#This is useful if you need to modify the queries.
Debug=true


 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…