• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Getting ArrayList from SQLite Database

 
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to get an array list which contains the identifiant of all the product for each category, knowing that the table must be of type integer :


at add, I think that there is an error
can you help me to fix it !!
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why do you think there is an error? TellTheDetails, and remember that we can't see what happens if you run this code.
 
clojure forum advocate
Posts: 3479
Mac Objective C Clojure
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not to mention that this query opens the door wide open for SQL injection.
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
because when i calculate the size of list i found it 0
or i have 7 elements !!
 
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
You'll have to do some debugging. I'd start with printing the exact query that's executed:

Does the query look like what you expected? When you do the same query manually against the database (with some database browser tool), do you get the expected result?

I don't know what API you're using to query the database, it doesn't look you're using the standard JDBC API.
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes, is the same !!
but the problem is not there is at add :


About the API i don't use the JDBC API
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's a problem, always the size is 0 !!
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have now jumped from a standard Java question (accessing from an ArrayList) back into a new Android-specific question. Generally for each new question you should create a new thread, and put it in the proper location, so folks expecting Java questions don't see Android questions without context.

Here is my guess: or more of leading questions. What do you put INTO the database in the COL_PRODUCT_NAME? Can you show the insert statement? What type do you define the column? Did you change your database so it stopped holding ... oh let's say String and started holding Integers? When you did that did you remember to increment the database version and write a correct update method?
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to get an array list which contains the identifiant of all the product for each category,
here's the code:

COL_ID_PRODUCT: (type int) column which contains the identifiant for each product
TABLE_PRODUCT:contains COL_ID_PRODUCT,COL_PRODUCT_NAME which contains the name for each product, COL_CATEGORY (type int) contains the ID of the category to which each product belongs.

To test my method, i just want to calculate the size of this tab :

When i debug this, the size n is 0 or i have 7 product in the category with ID=1 !!

 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nobody can help me
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's probably because you're ignoring most of what people tell you. You didn't follow up on most of what Jesper and Steve suggested.
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's work now !!
I changed <integer> by <Integer>
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I have sort of the same problem. I need to obtain the data in Chart Activity from the database class and use it to populate chart. Since it is dynamic chart I created an ArrayList of Integers, however how to populate it with integers from database class I have no idea.

so far I have come up with a method in Chart calss:





Class getHappyData in the database should return the integers ArrayList HappyList. And here I have an issue how to obtain the integers and put them into HappyList in Chart.class.




any advice would be much appreciated.

thank you for your time.
 
Whip out those weird instruments of science and probe away! I think it's a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic