This week's book giveaway is in the Go forum.
We're giving away four copies of Head First Go and have Jay McGavren on-line!
See this thread for details.
Win a copy of Head First Go this week in the Go 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
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

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

 
Greenhorn
Posts: 10
  • 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.
 
Marshal
Posts: 24199
54
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: 5654
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: 10
  • 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
Marshal
Posts: 24199
54
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.
 
Tick check! Okay, I guess that was just an itch. Oh wait! Just a tiny ad:
Become a Java guru with IntelliJ IDEA
https://www.jetbrains.com/idea/
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!