wood burning stoves*
The moose likes Struts and the fly likes errors occured...for database ..my god~kick my head~ Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "errors occured...for database ..my god~kick my head~" Watch "errors occured...for database ..my god~kick my head~" New topic
Author

errors occured...for database ..my god~kick my head~

wang wang
Greenhorn

Joined: Jul 08, 2003
Posts: 2
infomation of errors:
----------------------------------------------------------------
500 Servlet Exception
javax.servlet.UnavailableException: Initializing application data source
org.apache.struts.action.DATA_SOURCE
at org.apache.struts.action.ActionServlet.initModuleDataSources(ActionServlet.java:1091)
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:472)
at javax.servlet.GenericServlet.init(GenericServlet.java:82)
at com.caucho.server.http.Application.createServlet(Application.java:2755)
at com.caucho.server.http.Application.loadServlet(Application.java:2711)
at com.caucho.server.http.Application.initServlets(Application.java:1763)
at com.caucho.server.http.Application.init(Application.java:1698)
at com.caucho.server.http.VirtualHost.restartApplication(VirtualHost.java:1340)
at com.caucho.server.http.VirtualHost.getInvocation(VirtualHost.java:992)
at com.caucho.server.http.ServletServer.getInvocation(ServletServer.java:935)
at com.caucho.server.http.ServletServer.serviceTop(ServletServer.java:845)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:213)
at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:158)
at com.caucho.server.TcpConnection.run(TcpConnection.java:140)
at java.lang.Thread.run(Thread.java:534)
--------------------------------------------------------------------------------
Resin 2.0.4 (built Thu Nov 15 17:56:24 PST 2001)
---------------------------------------------------
struts-config.xml;
--------------------------
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<!--
This is the Struts configuration file for the example application,
using the proposed new syntax.
-->

<struts-config>
<!-- ========== Data Source Configuration =============================== -->
<data-sources>
<data-source>
<set-property property="autoCommit"
value="false"/>
<set-property property="description"
value="Example Data Source Configuration"/>
<set-property property="driverClass"
value="org.gjt.mm.mysql.Driver"/>
<set-property property="maxCount"
value="4"/>
<set-property property="minCount"
value="2"/>
<set-property property="password"
value="111"/>
<set-property property="url"
value="jdbc ostgresql://localhost:3306/stock"/>
<set-property property="user"
value="root"/>
</data-source>
</data-sources>

<!-- ========== form Bean Definitions =================================== -->
<form-beans>
<form-bean name="LookUpform" type="stock.LookUpform"/>
</form-beans>
<!-- ========== Action Mapping Definitions ============================== -->
<action-mappings>
<action path="/lookup"
type="stock.LookUpAction"
scope="request"
input="/index.jsp"
name="LookUpform">
<forward name="success" path="/quote.jsp"/>
<forward name="failure" path="/index.jsp"/>
</action>
</action-mappings>
<message-resources parameter="com.wiley.ApplicationResources"/>
</struts-config>
--------------------------------------------------------------
i dont know why!my godness~save me.
and i using struts1.1,when i replace the struts.jar(for struts 1.1) in struts.jar(1.0 version)database is ok!!!but LookUpAction can not work correctly!!!
wang wang
Greenhorn

Joined: Jul 08, 2003
Posts: 2
Action source-code:
-----------------------------
package stock;
import javax.servlet.ServletContext;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.SQLException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import java.io.IOException;
import org.apache.struts.action.Actionform;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public class LookUpAction extends Action{
/*protected Double getQuote(String symbol){
if(symbol.equalsIgnoreCase("SUN")){
return new Double(25.00);
}
return null;
}*/
protected Double getQuote(String symbol){
Double price=null;
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
ServletContext context = servlet.getServletContext();
DataSource dataSource = (DataSource)context.getAttribute(Actions.DATA_SOURCE_KEY);
try{
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");
}
}catch(SQLException e){
System.err.println(e.getMessage());
}finally{
rs=null;
stmt=null;
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");
if(form!=null){
LookUpform lookupform=(LookUpform)form;
String symbol=lookupform.getSymbol();
price=getQuote(symbol);
}
if(price==null){
target=new String ("failure");
}else{
request.setAttribute("PRICE",price);
}
return (mapping.findForward(target));
}
}
Jeremy Davis
Greenhorn

Joined: Feb 07, 2003
Posts: 17
You have:
DataSource dataSource = (DataSource)context.getAttribute(Actions.DATA_SOURCE_KEY);
Get rid of the "s" on the end of "Actions.DATA_SOURCE_KEY" ataSource dataSource = (DataSource)context.getAttribute(Action.DATA_SOURCE_KEY);
Hope this helps,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: errors occured...for database ..my god~kick my head~