File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes saving sql query to string[] Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "saving sql query to string[]" Watch "saving sql query to string[]" New topic
Author

saving sql query to string[]

Eduardo Ponce de Leon
Ranch Hand

Joined: May 13, 2009
Posts: 99
I basically want to display results from a SQL query to a simple website... I have my querey but when I try i to on my website i get no results and no erros...

This is my code



I cant figure why I am not able to display...the result in my DB is a list of names (50+)
Can anybody help!!
THANK YOU
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60991
    
  65

Step 1: if the DB access code is in a JSP, move it out to a Java class. First. Now. Before doing anything else.

Then test the class separately to make sure that it's doing what you expect it to do.

After that, you can call this class from your page controller and forward the List of results to the JSP for display.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Eduardo Ponce de Leon
Ranch Hand

Joined: May 13, 2009
Posts: 99
that shouldnt make a difference... If the code is right, it should work!!
Obviously there is something wrong in my code, because on my previous pages i have no problem
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Eduardo Ponce de Leon wrote:that shouldnt make a difference... If the code is right, it should work!!

Indeed it should. But since it doesn't work, it isn't right.

Does your debugger support JSPs?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60991
    
  65

One of the very very very many reasons not to put Java code in a JSP is testability. You can choose to take the advice of the senior members and follow best practices. Or you can continue to struggle. The choice is yours.
Eduardo Ponce de Leon
Ranch Hand

Joined: May 13, 2009
Posts: 99
to be hones i dont know if my DB access is in JSP. Yes i want to take advantage of your knowledge...
this is my code, what is next?

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Eduardo Ponce de Leon wrote:to be hones i dont know if my DB access is in JSP.


I'm sorry, am I correct in assuming that you don't know whether that code you posted is a JSP? Then yes, I can confirm that it's JSP code.

What should you do next? Well, JSP is an extremely poor environment for debugging code. Get your database code out of that JSP and put it into a plain old Java class. Get it working there.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: saving sql query to string[]