• 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

what's wrong with this code

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why is this code:-

Vector v = new Vector();
try {
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT acc_id FROM mytable");

while(rs.next()) {
v.addElement(rs.getString("acc_id"));
}
rs.close();

giving me this warning:-
warning: [unchecked] unchecked call to add(E) as a member of the raw type java.util.Vector
v.addElement(rs.getString("acc_id"));

please can someone explain to me why and what to do next

joe
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look at the Generics part of the Java Tutorial. The last part where it says "unchecked warnings" will help you. Briefly, since Java5, Vector has been a generic class. Read the tutorial for more details.

And don't use Vector. Use ArrayList instead, and declare the type of the object as java.util.List.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please do not post the same question multiple times.
 
You've gotta fight it! Don't give in! Read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic