aspose file tools
The moose likes Java in General and the fly likes what's wrong with this code Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "what Watch "what New topic
Author

what's wrong with this code

joseph okon
Ranch Hand

Joined: Dec 07, 2004
Posts: 63
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
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32675
    
    4
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.
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12921
    
    3

Please do not post the same question multiple times.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what's wrong with this code
 
Similar Threads
error unchecked call to addElement in vector
Dynamic GridLayout Paint
Why am I getting this error?
somebody help me out
Problem with Vector