Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java Open Source > BOOK: Professional Jakarta Struts
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional Jakarta Struts
This is the forum to discuss the Wrox book Professional Jakarta Struts by James Goodwill, Richard Hightower; ISBN: 9780764544378
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Jakarta Struts section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old May 25th, 2005, 02:57 PM
Registered User
 
Join Date: May 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Database Access in Struts

I am new to struts.Trying to learn thru this book.
I am referring to Chapter 11 in the book proffesional jakartha struts 1.1.
I have the LookupAction.java file with the Data source code etc.
But when I try to compile javac LookupAction.java
it gives an error
cannot resolve symbol
method getDataSource(javax.http.servlet.HttpServletReques t).

What could be the error.
I am pasting my code below.

******************************
package ch03;

import java.lang.*;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import java.util.*;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;



public class LookupAction extends Action
{
   protected Double getQuote(HttpServletRequest request,String symbol)
   {
    Double price=null;
    Connection conn=null;
    Statement stmt=null;
    ResultSet rs=null;
    DataSource dataSource = null;
    try
    {
        dataSource = getDataSource(request);
        conn=dataSource.getConnection();
        stmt=conn.createStatement();
        rs=stmt.executeQuery("select * from stocks where" +"symbol='"+symbol+"'");
        if(rs.next())
        {
            double tmp=0;
            tmp=rs.getDouble("price");
            price = new Double(tmp);
            System.err.println("Price:" +price);
        }
        else
        {
            System.err.println("Symbol not found retutrning null");
        }
    }
    catch(SQLException e)
    {
            System.err.println(e.getMessage());
    }

    finally
    {
        if (rs!=null)
        {
            try
            {
                rs.close();
            }
            catch(SQLException sqle)
            {
                System.err.println(sqle.getMessage());
            }
            rs=null;

        }
        if (stmt!=null)
        {
            try
            {
                stmt.close();
            }
            catch(SQLException sqle)
            {
                System.err.println(sqle.getMessage());
            }
            stmt=null;

        }
        if (conn!=null)
        {
            try
            {
                conn.close();
            }
            catch(SQLException sqle)
            {
                System.err.println(sqle.getMessage());
            }
            conn=null;

        }
        }
    return price;

  }


public ActionForward execute(ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response)
    throws IOException, ServletException
{

    Double price=null;
    String target = new String("success");
        String symbol = null;

    if ( form != null )
    {
      LookupForm lookupForm = (LookupForm)form;
      symbol = lookupForm.getSymbol();
      price = getQuote(request,symbol);
    }

    // if price is null, set the target to failure
    if ( price == null )
    {

      target = new String("failure");
/* ActionErrors errors = new ActionErrors();
    errors.add("symbol",new ActionError("errors.lookup.unknown",symbol));
    if( errors.isEmpty() )
    {
        saveErrors(request, errors);
    }*/

    }
    else
    {
      request.setAttribute("PRICE", price);
    }
    // Forward to the appropriate View
    return (mapping.findForward(target));
  }
}
**********************
Any help will be appretiated
How to rectify the error?
Thanks in advance


  #2 (permalink)  
Old August 25th, 2005, 03:24 PM
Registered User
 
Join Date: Aug 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yeah, I've got the same problem. I have had a BUNCH of problems with this book, and I am sorry I bought it (mostly related to taglib problems between various struts versions.) I am trying to do an app for work and I thought this book would help.. big mistake.

Anyways, I have been able to determine that this is supposed to be in the base Action class, and it isn't. Could be a version issues between 1.0/1.1/1.2. I have to work alongside my company's own Struts app for what I am writing and it is older than dirt, so I have to stay with the older struts stuff for now :( I am right now trying to implement my own version of the method, knowing that it has to retrieve the DataSource from the ServletContext.

  #3 (permalink)  
Old June 22nd, 2006, 11:49 AM
Registered User
 
Join Date: Jun 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi did u get how to connect to DB? I am also trying same thing. I got error HTTPRequest request can not resolve symbol in Quote method


Quote:
quote:Originally posted by sunu
 I am new to struts.Trying to learn thru this book.
I am referring to Chapter 11 in the book proffesional jakartha struts 1.1.
I have the LookupAction.java file with the Data source code etc.
But when I try to compile javac LookupAction.java
it gives an error
cannot resolve symbol
method getDataSource(javax.http.servlet.HttpServletReques t).

What could be the error.
I am pasting my code below.

******************************
package ch03;

import java.lang.*;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import java.util.*;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;



public class LookupAction extends Action
{
   protected Double getQuote(HttpServletRequest request,String symbol)
   {
    Double price=null;
    Connection conn=null;
    Statement stmt=null;
    ResultSet rs=null;
    DataSource dataSource = null;
    try
    {
        dataSource = getDataSource(request);
        conn=dataSource.getConnection();
        stmt=conn.createStatement();
        rs=stmt.executeQuery("select * from stocks where" +"symbol='"+symbol+"'");
        if(rs.next())
        {
            double tmp=0;
            tmp=rs.getDouble("price");
            price = new Double(tmp);
            System.err.println("Price:" +price);
        }
        else
        {
            System.err.println("Symbol not found retutrning null");
        }
    }
    catch(SQLException e)
    {
            System.err.println(e.getMessage());
    }

    finally
    {
        if (rs!=null)
        {
            try
            {
                rs.close();
            }
            catch(SQLException sqle)
            {
                System.err.println(sqle.getMessage());
            }
            rs=null;

        }
        if (stmt!=null)
        {
            try
            {
                stmt.close();
            }
            catch(SQLException sqle)
            {
                System.err.println(sqle.getMessage());
            }
            stmt=null;

        }
        if (conn!=null)
        {
            try
            {
                conn.close();
            }
            catch(SQLException sqle)
            {
                System.err.println(sqle.getMessage());
            }
            conn=null;

        }
        }
    return price;

  }


public ActionForward execute(ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response)
    throws IOException, ServletException
{

    Double price=null;
    String target = new String("success");
        String symbol = null;

    if ( form != null )
    {
      LookupForm lookupForm = (LookupForm)form;
      symbol = lookupForm.getSymbol();
      price = getQuote(request,symbol);
    }

    // if price is null, set the target to failure
    if ( price == null )
    {

      target = new String("failure");
/* ActionErrors errors = new ActionErrors();
    errors.add("symbol",new ActionError("errors.lookup.unknown",symbol));
    if( errors.isEmpty() )
    {
        saveErrors(request, errors);
    }*/

    }
    else
    {
      request.setAttribute("PRICE", price);
    }
    // Forward to the appropriate View
    return (mapping.findForward(target));
  }
}
**********************
Any help will be appretiated
How to rectify the error?
Thanks in advance


  #4 (permalink)  
Old August 1st, 2006, 12:18 PM
Registered User
 
Join Date: Aug 2006
Location: Stockholm, N.A., Sweden.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

From my point of view this statement lacks a blank
        rs=stmt.executeQuery("select * from stocks where" +"symbol='"+symbol+"'");
should be
        rs=stmt.executeQuery("select * from stocks where " +"symbol='"+symbol+"'");
or even simpler
        rs=stmt.executeQuery("select * from stocks where symbol='"+symbol+"'");
otherwise java concatenates to "wheresymbol" which is a symbol that sql can't make anything of. Other errors might be there but i haven't found any, apart from some minor misspellings.
  #5 (permalink)  
Old November 20th, 2006, 08:32 AM
Registered User
 
Join Date: Nov 2006
Location: Bangalore, , India.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Though your post is very old, i this will help the people who get similar errors..
the error you get is because of importing unwanted class..

the getDatasource(request) is not in javax.sql package...but in
struts.action.Action
when you remove the import statement, this error will go off...

i hope this helps you.
Cheers,
Pradeep:)
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Connecting MS Access using Struts roopesh_dubey Struts 0 February 18th, 2007 02:43 AM
Connecting to oracle database in struts Manvi Struts 3 August 7th, 2006 11:53 PM
login screen in struts and mysql database mill3prog7@yahoo.co.in Struts 1 May 4th, 2006 10:07 AM
Struts database connection how? feen4u BOOK: Professional Jakarta Struts 1 January 10th, 2005 01:47 PM
struts with database rajkumares Servlets 0 October 12th, 2004 01:21 AM



All times are GMT -4. The time now is 10:35 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.