SQL Problem with date variable

Having issue with my date argument. Not sure what else to do to get it to accept.

date = system.date.now()
value1 = system.date.format(date, "yyyy/MM/dd HH:mm:ss")
system.gui.messageBox(value1)

query = ''' SELECT Rtrim(UID) AS [Row Number], RTRIM(PaintColor) AS [Paint Color], RTRIM(PaintPN) AS [Paint PN], RTRIM(StartTime) AS [Planed Start Time],
            RTRIM(StopTime) AS [Planed Stop Time], RTRIM(PlanDate) AS [Planed Date], RTRIM(EnteredBy) AS [Entered By],Shift 
            FROM SF_Paint_Schedule WHERE PlanDate >= ? '''         
                 
args = (value1)
data = system.db.runPrepQuery(query, args)

system.tag.write("[Client]Paint_Schedule",data)

Keep Getting this Error:

Traceback (most recent call last):
File “event:actionPerformed”, line 12, in
java.lang.ClassCastException: java.lang.ClassCastException: Cannot coerce value ‘2019/03/08 08:45:10’ into type: class [Ljava.lang.Object;
caused by ClassCastException: Cannot coerce value ‘2019/03/08 08:45:10’ into type: class [Ljava.lang.Object;
Ignition v7.9.10 (b2018112821)
Java: Oracle Corporation 1.8.0_201

Thanks in advance for taking a look

Try this instead

import datetime
date = datetime.datetime.now()

When you are using parameter substitution, don’t convert your date to a string. JDBC will take care of it for you – that’s the point. Also, parentheses don’t make a tuple, commas do. It’s better to use square brackets to make a list for args.

args = [system.date.now()]

Consider always using Java’s native Date and Calendar types instead of python’s versions. Most usage of python’s library objects within java subsystems invokes a complicated type cast.

1 Like

Pturmel. Thank you again sir. You have been helpful to me many times in the past I appreciate it. I also want to thank you dkhayes117 for your contribution as well. I am working good now.