• 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
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

Error : Calling MySQL stored procedure from java application

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
this is the stored procedure in MySQL



this is the java application


but, i'm getting this exception


how do i overcome this exception ??
 
Marshal
Posts: 3257
487
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guessing it is because you cannot name your SP sum since it is a reserved word.  I tried your same code with a different name it and worked (I used command line but I expect it will be successful using JDBC as well):
 
Saloon Keeper
Posts: 22784
153
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, the backticks on the procedure definition override the reservation on the name "sum", although it's stil better to use a (hopefully more descriptive) name and avoid that mess. There were no backticks or qualifiers on the Java code's SQL "call" statement, however, so the wrong "sum" was being referenced. Again, a more meaningful (and unreserved) procedure name would be preferable.

Also, lose the Class.forName(). It has probably been 15 years now since that statement became obsolete.

And for security's sake, use some other database user ID than root!

 
Ron McLeod
Marshal
Posts: 3257
487
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tim, you're right; using backticks around the procedure name when calling does resolve the runtime problem.
 
reply
    Bookmark Topic Watch Topic
  • New Topic