If you want to set an argument to the given date value, you should use the setDate()
method of your PreparedStatement
instance.
However this method needs a java.sql.Date
instance, and if your date is a java.util.Date
, then you have to convert it: new java.sql.Date(java_util_date.getTime());
EG:
try ( PreparedStatement ps = con.prepareStatement( "SELECT * FROM table WHERE dat >= ?" ))
{
ps.setDate(1, new java.sql.Date( System.currentMillis() ) );
try ( ResultSet rs = ps.executeQuery() )
{
while ( rs.next() )
{
// process the row in rs
}
}
}
Edit
For stored procedure use the following syntax in the SQL query:
{call stored_procedure(?)}
Also, use executeUpdate()
instead of executeQuery()
, if your stored procedure does not return a ResultSet
...
(If i remember correctly, there were some issues with the call
keyword, especially with the case. So try CALL
if call
does not work...)