I have MSSQL procedure:
my_proc
I get data from java
String sql = "exec my_proc '2016-01-01','2016-01-20','2016-01-01'";
stmt = connection.prepareStatement(sql);
rs = stmt.executeQuery();
and get all data fine!
but if I use
String msisdn, String startDate, String endDate
String sql = "exec my_proc ?,?,?";
stmt = connection.prepareStatement(sql);
stmt.setString(1, msisdn);
stmt.setString(2, startDate);
stmt.setString(3, endDate);
rs = stmt.executeQuery();
I get error:
com.microsoft.sqlserver.jdbc.SQLServerException: Error converting data type varchar to datetime.
In procedure I have variables:
@Startdtin datetime,
@Enddtin datetime,
@msisdnin varchar(18)
I tried use
stmt.setTimestamp(2, startDate); //startDate - convert to Timestamp
and
stmt.setDate(2, startDate); //startDate - convert to Date (sql and util)
It is not helped. How pass date to PreparedStatement
correctly`?