• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Get list size  RSS feed

 
Ranch Hand
Posts: 570
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have multiple query in Java and trying to add them in a list. I can get totalList and l but don't know how to get dataList.


  
JDBC

   
 
Saloon Keeper
Posts: 5003
54
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On line 19 dataList is being overwritten each time around the loop, so, only the last one will display in your print.
 
John Joe
Ranch Hand
Posts: 570
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:On line 19 dataList is being overwritten each time around the loop, so, only the last one will display in your print.


Is there any way I can get the dataList size and at the same time I can add everything up into list ? Thanks
 
John Joe
Ranch Hand
Posts: 570
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use but get below errors
 
John Joe
Ranch Hand
Posts: 570
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please help !
 
Marshal
Posts: 6121
418
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I find it difficult to follow your method. Most likely because it does many things. I'd suggest start by decomposing it into smaller pieces (meaning several other methods), and might you'll notice some programming errors of yours yourself. When something doesn't work, always try to decompose/refactor, make it smaller, easier to understand - so you could be sure you didn't introduce a bug. More better of course would be to write right away small methods which clearly expresses intent - that usually saves time in a longer term.
 
Liutauras Vilda
Marshal
Posts: 6121
418
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Method names matter a lot.

You got some method named:
getFromText() - I'm wondering what that might be. Get from text what? Character, first one or last one? Maybe amount of characters text contains? Maybe vowels? Maybe user ID? Home address?
 
Sheriff
Posts: 5289
142
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

John Joe wrote:I use but get below errors


So let's look at the error message and see what we can discern: You're trying to add an element to a List of Object[].  So each element needs to be an Object[].  We don't have the code for getFromText() but from the error we can tell that it returns a List.  So you're trying to add an element to dataList that is a List, but you've defined dataList as a List of Object[].

So you need to decide if you want dataList to be a List of Lists or if getFromText() should return an Object[] instead of a List.
 
Knute Snortum
Sheriff
Posts: 5289
142
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

John Joe wrote:Please help !


EaseUp
PatienceIsAVirtue
 
John Joe
Ranch Hand
Posts: 570
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm able to solve it

I use addAll instead of add and change the return type of getFromText from List to List<Object[]>
JDBC


 
Knute Snortum
Sheriff
Posts: 5289
142
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for posting the solution, and good job.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!