• 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

Not receiving a count from select

 
Ranch Hand
Posts: 73
2
IntelliJ IDE Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure why I'm not receiving a count from the following code. It seems pretty straight forward, and yes, there is an id of '24' in this table and field. I think the problem resides somehow with the query and I may not be seeing it.

My Problem:
The Java code with the SQLite query will not return a count.

What I've done:
I've copied the concatenated 'countIDs' string value from the variable (i.e. statement below) and executed it manually against SQLite and it returns the correct count.
I've tried passing the statement directly within the "sConn.preparedStatemement(...), bypassing the string variable and it still doesn't return the correct result.
I've double checked the documentation for SQLite COUNT() function queries. (http://www.sqlitetutorial.net/sqlite-count-function/)
I've messed with using and eliminating the 'while' statement and tried different result set functions.

This is the actual Java concatenated string: SELECT COUNT(*) FROM Notes WHERE SourceID = 24



NotesTable.JPG
[Thumbnail for NotesTable.JPG]
Notes table with SourceID field and value (24)
 
Scott Vallery
Ranch Hand
Posts: 73
2
IntelliJ IDE Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I figure it out. The row in which the value existed was being deleted before the data could be captured through the query.

Sorry for the trouble, but thanks!
Scott
 
Bartender
Posts: 1357
39
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Scott Vallery wrote:
Sorry for the trouble, but thanks!
Scott



Thanks for letting us know you have solved your problem. And remember to never be afraid of asking for help here at Coderanch!
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since you're already using PreparedStatement, you should use it for any user input. Unfortunately table and column names cannot be parameters to a PreparedStatement, but the value should be:

As for the table name and column name (field), you should validate that these are valid. Preferably you fill them in somewhere in code. If not, and they come from user input, you should at least validate they come from a white list, or have the correct format. Otherwise you could end up being visited by little Bobby Tables.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic