问题描述
java.sql.Date d = new java.sql.Date(System.currentTimeMillis()); // I know what this does
d.setYear(d.getYear() - 2);// I know what this does
hist_sections.setDate(1, d);// I am not sure what this does and I can't seem to find documentation for this.
感谢您的帮助
Thanks for the help
推荐答案
n
n
一个 int ,它指示参数编号.
An int that indicates the parameter number.
x
x
日期对象.
现在参考一个示例- PreparedStatement:setDate(int parameterIndex,Date x) [ ^ ].
这里的查询指定为...
Now refer one example - PreparedStatement: setDate(int parameterIndex, Date x)[^].
Here the query is specified like...
String query = "insert into date_table(id, date_column) values(?, ?)";
其中id
,date_column
是期望的参数.
然后...
Where id
, date_column
are the parameters it is expecting.
And after that...
pstmt.setString(1, "0001");
java.sql.Date date = getCurrentJavaSqlDate();
pstmt.setDate(2, date);
这里的1和2是参数索引.含义pstmt.setString(1, "0001");
表示查询的id
,而pstmt.setDate(2, date);
表示查询的date_column
.
因此,在您的代码hist_sections.setDate(1, d);
中,查询期望位置1处的日期参数.
希望您能理解这个概念.
Here 1 and 2 are the Parameter Index. Meaning pstmt.setString(1, "0001");
implies to id
and pstmt.setDate(2, date);
implies to date_column
of the query.
So, in your code hist_sections.setDate(1, d);
, the query is expecting date parameter at position 1.
Hope you get the concept.
这篇关于PreparedStatement setDate方法(int,java.sql.Date)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!