This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Grokking Bitcoin and have Kalle Rosenbaum on-line!
See this thread for details.
Win a copy of Grokking Bitcoin this week in the Cloud/Virtualization forum!
  • 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
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

Not receiving a count from select  RSS feed

 
Ranch Hand
Posts: 45
2
Eclipse IDE IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • 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: 45
2
Eclipse IDE IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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: 1120
38
IBM DB2 Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • 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: 21718
102
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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.
 
I RELEASE YOU! (for now .... ) Feel free to peruse this tiny ad:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!