Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help with sql query fetching data from database and displaying it

 
Jicksy John
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator


Edited the code and it is working.



It's working
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic