Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
See more:
C#
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
Posted
v2
Comments
What is hist_sections?
rudolph098 19-Aug-13 9:35am    
its a variable of type ResultSet
rudolph098 19-Aug-13 9:41am    
thank you, but the documentation does little to nothing to answer my question.
Please check my answer. I have tried to explain you.

1 solution

As Sudhakar Shinde has given you the documentation link[^], from that link it is clear that...
Quote:


n


An int that indicates the parameter number.



x


A Date object.



Now refer one example - PreparedStatement: setDate(int parameterIndex, Date x)[^].

Here the query is specified like...
Java
String query = "insert into date_table(id, date_column) values(?, ?)";

Where id, date_column are the parameters it is expecting.

And after that...
Java
pstmt.setString(1, "0001");
java.sql.Date date = getCurrentJavaSqlDate();
pstmt.setDate(2, date);

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.
 
Share this answer
 
Comments
rudolph098 19-Aug-13 10:15am    
Is there a way I can mimic this functionality in c#?.
In C#, it is implemented differently.

Check Inserting datetime from C# to SqlServer for one example.
rudolph098 19-Aug-13 10:25am    
thank you man, really greatful
Most Welcome. My Pleasure... :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900