• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Ambiguous class problem

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have created a servlet which enters html form input into a db2 database, and it is all working nicely with integer values. However, I want to perform some date and time calculations calculations on the form input, for which I need the Date class. To perform the sql needed for the database entry, I "import java.sql.*;". In order to perform the date calculations, I "import java.util.*;". The date calulations work fine in a servlet which does not have java.sql imported. However, when I try to put this calculation into the database entry servlet, I get
"Ambiguous class: java.util.Date and java.sql.Date"
removing "import.java.util.*;" means that it cannot compile the Date class (i.e. java.sql.Date does something else). How can I make it ignore java.sql.Date?
Thanks,
James
[This message has been edited by James Hewitt (edited July 10, 2001).]
 
Saloon Keeper
Posts: 27764
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yup, it's a nuisance. You're going to have to explicitly qualify all Date declarations and casts. There are, unfortunately, some critical differences in the two different Date classes, so the compiler has to know which one you're using at any given time. Among other things, the SQL date has no time component.
Once you declare implicit class pedigrees using the import statement, Java has no prioritizing mechanism to prefer one implicit pedigree to another. It's just as well, since some extremely nasty bugs could creep in that way.
 
James Hewitt
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right, that's fixed it. Thanks very much,
James
 
reply
    Bookmark Topic Watch Topic
  • New Topic