• 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

missing return statement error

 
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in following program



i am getting following error


javac -d ../ Bean.java
Bean.java:65: missing return statement
}
^


[Edit - fixing page width]
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I try to compile your code, I don't get any compiler errors. It seems to me that you're compiling a file which differs from the one you've posted here.

If you use an IDE for your work, I'd suggest to reformat your code, as it is very unclear in its current form.

Anyway, there are some other issues with your current code:

* You're using generic raw types (eg. List instead of List<String>). This tutorial might help you to use generics better.

* The SQL statement stored in variable query is syntactically incorrect.

* You're throwing an Exception. It would be better to throw some more specific exception, for details, see this.

* In your catch clause, you're printing the stack trace (which is good), but then allow your code to return the list.
When an exception happens, the caller of your method won't know about it and will process the returned list as if no error occurred.
You should throw an exception from the inside of your catch clause. The previous link contains some details on this too.
 
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
Megha, your example shows how problematic it can be to trouble shoot code that does not have consistent indentation. I've changed the indentation in your code to always use 4 spaces, and it does show that the only return statement is exactly at the end of the method. I too get no compiler error.

One piece of advice though - do not use OracleDataSource, but instead use javax.sql.DataSource. It's the interface that OracleDataSource implements, but using this allows you to switch to a different database system without having to change your code, only your configuration.
 
It would give a normal human mental abilities to rival mine. To think it is just a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic