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

Syntax failure trying to check a MySQL database for entries  RSS feed

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello there!

I'm brand new to Java and to MySQL too. On the tutorials I've been watching I've followed step by step but the tutorial itself is a bit outdated, and when I enter the below code I get an error stating that the syntax is not correct.

Here's the code



Here's the error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*) as count from minion where id=2' at line 1

Anyone able to help with this?

Thanks a lot - this is ALSO the first time I've ever logged into or used a forum, so I sincerely apologise if I'm using it wrong. Just let me know.

Thank you.

Stephen.
 
Sheriff
Posts: 24369
55
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Stephen, welcome to the Ranch!

The error message is just complaining about your SQL statement, which is



Which looks fine to me. Except I've never tried putting a space between "count" and "(*)" so maybe you're not supposed to do that. Try "count(*)" instead of "count (*)"?
 
Bartender
Posts: 5774
56
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seeing as how you are getting the count by index and not by name, you might try leaving off the "as count".
 
Stephen Pillinger
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you!

Should have paid more attention to the syntax itself, that's exactly what it was (putting a space after 'count').

Good start at the ranch!!
 
Paul Clapham
Sheriff
Posts: 24369
55
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stephen Pillinger wrote:Should have paid more attention to the syntax itself, that's exactly what it was (putting a space after 'count').



I've been writing SQL for a very long time and I didn't know about that rule. And even the MySQL documentation about counting rows doesn't mention that you aren't allowed to put whitespace between "count" and "(".

But then, as I said, I never tried putting that whitespace in there. It's just not something I would ever find necessary; maybe that's because none of the examples in the documentation include that whitespace.
 
The two armies met. But instead of battle, they decided to eat some pie and contemplate 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!