Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieve MS Access Date using JDBC

Status
Not open for further replies.

cmmrfrds

Programmer
Feb 13, 2000
4,690
US
How do I retrieve a microsoft access date field. Here is my code in a case statement.<br>ResultSet rs;<br><br>case Types.DATE:<br>&nbsp;&nbsp;currentRow.addElement(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new Date( rs.getDate(i)) );<br>&nbsp;&nbsp;break;<br>This gives an error that &quot;reference to date is ambigious - in both java.util and java.sql&quot;.<br>Changing to this gives another type of error<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Date.valueof( rs.getDate(i)) );<br>error is: &quot;no method with java.sql.Date &quot;<br><br>Do I need to break the date down into individual parts such as year, month, day. if so, how would it look in code.<br><br>Thank you,<br>
 
hi,<br><br><br>your problem is quite simple.<br><br>Date class can be found in the following 2 packages:-<br><br>java.sql<br>java.util<br><br>So in case you import all the classes from the above 2 packages then the compiler will complain that &quot;new Date(..&quot; is ambigous because it will not know which of the 2 Date classes to instantiate.<br><br><br>The solution would be to use...<br>&nbsp;&nbsp;&quot; new java.sql.Date(... &quot; or<br>&nbsp;&nbsp;&quot;new java.util.Date(...&quot; depending on which Date you require.<br><br><br>Regards
 
Thank you for the information. I guess my real question is that I don't understand what kind of data comes back from MS Access in a date field. Apparently, Java picks up the field as a DATE type, but I don't know how to parse the field. I tried using getLong, which compiles but gives an exception. I tried creating a new String field of the data but get an arrayindex out of bound error. Do you have a code sample on how to manipulate a date field from MS Access or any other SQL database?<br><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top