Sri Sri - 4 months ago 17
SQL Question

how to parse date n java to oracle/sql query?

I have a Query like

String query = "Select * from Orders where ordername = ? and orderDate > SYSDATE - 2 ";

i will pass
from UI or some constant ("20-9-2016").

orderDate=SYSDATE - 2 --> instead of "2" i will send lastDate.

Is it correct? SYSDATE oracle function and "2" before constant. now "2" can be user input.

How to write a query in java

String query = "Select * from Orders where ordername = ? and orderDate > SYSDATE - ? ";

Is above query correct ? how to write query

public class CheckOrders extends MappingSqlQuery<Object>{
public PendingOrderExists() {
super(dataSource, queryConfig
super.declareParameter(new SqlParameter("ORDERNAME", Types.VARCHAR));
//orderdate ? how to declare parameter here


for sysdate-? the ? parameter is to be set object of java.sql.Date class instead of java.util.Date class. java.sql.Date inherits java.util.Date. java.sql.Date(long time) here long is number of milliseconds lapsed since jan1,1979.

GregorianCalendar gc=new GregorianCalendar(2000, 25, 2);

java.util.Date dt=gc.getTime(); long lg=dt.getTime(); java.sql.Date sqldt=new java.sql.Date(lg); '

pass sqldt object in setDate() method of preparedstatement instance.

hope this works