0

可能重复:
TSQL:来自字符串错误的日期时间

我无法将字符串转换为日期时间。我正在使用 SQL Server 2005。

String frmDate="03/09/2012";
String toDate="04/09/2012";

SimpleDateFormat formater = new SimpleDateFormat("dd/MM/yyyy");
Date frmDate1 = formater.parse(frmDate);
Date toDate1=formater.parse(toDate);


 String query3="select * from dbo.Monthly_PFSPL "  +  
    "where Convert (datetime,Added_Date,103) "  +  
"between '"+frmDate1+"' and '"+toDate1+"' ";
        rsobj1=stat2.executeQuery(query3);

我得到了这个例外:

java.sql.SQLException: Conversion failed when converting datetime from character string
4

1 回答 1

1

You must have to use PreparedStatement and parameterized SQL statement.

String query="select * from dbo.Monthly_PFSPL where Convert(datetime,Added_Date,103) between  ? and ?";
于 2012-09-03T06:31:07.133 回答