Hi..
I'm trying to connect MySQL thru
Struts config on
Tomcat 4.1 but I get the error while trying to load the application into the server.
The error is..
org.apache.struts.action.ActionServlet initModuleDataSources
SEVERE: Initializing application data source org.apache.struts.action.DATA_SOURCE
java.lang.NullPointerException
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1355)
......
I've configured the database in struts config file as
<?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">
<struts-config>
<data-sources>
<data-source>
<set-property property="driverClass" value="org.gjt.mm.mysql.Driver" />
<set-property property="url" value="jdbc:mysql://localhost/stocks" />
<set-property property="maxCount" value="5"/>
<set-property property="minCount" value="1"/>
<set-property property="user" value="root"/>
<set-property property="password" value="admin"/>
</data-source>
</data-sources>
<form-beans>
<form-bean name="lookupForm" type="wiley.LookupForm"/>
</form-beans>
<action-mappings>
<action path="/Lookup"
type="wiley.LookupAction"
name="lookupForm"
validate="true"
input="/index.jsp">
<forward name="success" path="/quote.jsp"/>
<forward name="failure" path="/index.jsp"/>
</action>
</action-mappings>
<controller processorClass="wiley.WileyRequestProcessor" />
<message-resources parameter="wiley.ApplicationResources"/>
</struts-config>
But if I comment out the <data-sources> part and prepare the connection in Action class then it works
DriverManager.registerDriver(new org.gjt.mm.mysql.Driver());
conn = DriverManager.getConnection("jdbc:mysql://localhost/stocks","root","admin");
as I get the queries executed successfully.
And also if I use the following code to get Data Source
DataSource dataSource = (DataSource) servlet.getServletContext().getAttribute(Action.DATA_SOURCE_KEY);
I get the compile error Action.DATA_SOURCE_KEY can not be resolved.
I will need this to be resolved too after able to connect to the database thru struts config.
Please help me out to resolve the problem.