This is a discussion on "Cannot Find Symbol" when I trying Vector to ArrayList within the Java Programming forums, part of the Software Development category; I am changing from Vectors to use Arraylists with the new generics arraylists. My original code to read an SQL ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| I am changing from Vectors to use Arraylists with the new generics arraylists. My original code to read an SQL table and save the rows into a Vector: Code: private Vector llenaVectorConceptos(Vector VectorConceptos) {
ResultSet rs=null;
Vector vectorConceptos = new Vector();
try{
rs=stmt.executeQuery("Select * from Conceptos order by CONCEPTODESCRIPCION");
while(rs.next())
{
vectorConceptos.add(rs.getString("CONCEPTODESCRIPCION") + " > " + rs.getString("TIPO") + " > " + rs.getString("NUMCONCEPTO"));
}
}
catch(SQLException e){
System.out.println(e);
}
mdbc.close(rs);
return vectorConceptos;
} See the new code: Code: private ArraList llenaVectorConceptos(ArraList VectorConceptos) {
ResultSet rs=null;
ArraList<String> vectorConceptos = new ArraList<String>();
try{
rs=stmt.executeQuery("Select * from Conceptos order by CONCEPTODESCRIPCION");
while(rs.next())
{
vectorConceptos.add(rs.getString("CONCEPTODESCRIPCION"), rs.getString("TIPO"));
}
}
catch(SQLException e){
System.out.println(e);
}
mdbc.close(rs);
return vectorConceptos;
} Code: vectorConceptos.add(rs.getString("CONCEPTODESCRIPCION"), rs.getString("TIPO")); symbol : method add(java.lang.String,java.lang.String) location: class java.util.ArrayList<java.lang.String> vectorConceptos.add(rs.getString("CONCEPTODESCRIPC ION"), rs.getString("TIPO")); Is any Idea?
__________________ cheers Aman |
| Sponsored Links |
| |||
| mm…fine… I think i found the problem. the .add method for the arraylist only accept (1) value, i am trying to enter (2) values: vectorConceptos.add(rs.getString("CONCEPTODESCRIPC ION"), rs.getString("TIPO")); When i change the statement to : vectorConceptos.add(rs.getString("CONCEPTODESCRIPC ION")); the compilation message disappears. But now i have a new problem after changing this, I need an array with two columns, i mean, 1st column to hold the "CONCEPTODESCRIPCION" and a 2nd column to hold the "TIPO". Can it be possible using this kind of arraylis or i need another arraylist? Some example? Thanks again... |
| |||
| Hi You've changed Vector to ArrayList ok. It looks like you are also trying to change what you store in your collection. Previously you were storing a single String, now you want to store a more complex collection of information. You have a variety of options. One simple option is to use a String array. Code: ArrayList<String[]> vectorConceptos = new ArrayList<String[]>();
vectorConceptos.add(new String[] {rs.getString("CONCEPTODESCRIPCION"), rs.getString("TIPO")});
__________________ S.VinothkumaR Behind me is infinite power, Before me is Endless Possibility, Around me is Boundless Opportunity, Why should I fear! |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| What is the use of " - > " symbol in PHP? | S.Vinothkumar | PHP Programming | 4 | 11-04-2007 10:58 PM |
| I keep getting "Data Missing" when I click the "back" button in my browser. How can I | oxygen | HTML, CSS and Javascript Coding Techniques | 1 | 07-28-2007 01:12 AM |
| Diffrence between a "assignment operator" and a "copy constructor" | Sabari | C and C++ Programming | 1 | 07-24-2007 05:00 AM |
| Difference between "vector" and "array"? | Sabari | C and C++ Programming | 1 | 07-24-2007 04:33 AM |
| Why do I get "HTTP 500" error(or "(DLL)initialization routine failed")in my browser? | kingmaker | ASP and ASP.NET Programming | 1 | 07-20-2007 04:38 AM |