• 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

help with sql query fetching data from database and displaying it

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



This is my code

I am trying to fetch the content of afile from the database and use it in place of "/home/jj/Projects/SPAM/SOURCE CODE/e-mails/spam3.txt'. But I'm not able to fetch the adress from database with the query above. (In afile: path is stored)

I have given the run time code But it doesn't display anything.

But IP address is getting printed correctly in the previous step.

Any help would be appreciated, little urgent

Thank you in advance
 
Jicksy John
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Edited the code and it is working.



It's working
 
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
Great that you figured it out yourself!

There are still a few problems with your code. First of all, it is really a bad idea to catch an exception and do nothing, such as: When the exception actually occurs, your code will silently ignore it and continue. These bugs are very hard to understand ("my code doesn't fail but also doesn't do what it should"), so it's a good idea to get the code right at the first try.

I would even discourage using justIt's somewhat better than the above, but in real life people don't look at the logs or into the console very often, so these bugs tend to get overlooked anyway. The best approach in my opinion is to throw a RuntimeException with a good description of the problem and let it be. Your application might then catch and somehow process unchecked exceptions at the top level globally, or it would fail when it occurs, which is actually a very good and desirable outcome for unexpected exceptions.

It is also really necessary to correctly close the resources in the finally clause. Unless you're on Java 7, where you could (and should) use the try-with-resources statement that takes care of it all on its own.

And lastly, it's much better (and generally easier) to use PreparedStatement instead of concatenating the values into the SQL statements. The most important reasons are summed up nicely here.
 
Morning came much too soon and it brought along a friend named Margarita Hangover, and 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