acsess DB with struts:Error

M

marcelino

Hi,

still I'm a newbie handling struts. I tried to expand the
struts-example with a mysql DB-Connection called test. I can access
the example-welcome-site, but trying to activate the link to my site I
become this error:

ERROR: User database not loaded -- check servlet container logs for
error messages.

In the logs I find this two striking errors:

1)
2004-02-04 19:13:44 StandardContext[/test_struts]: Servlet
/test_struts threw load() exception
javax.servlet.ServletException: Servlet.init() for servlet action
threw exception at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:963)
etc.

2)
----- Root Cause -----
java.lang.NoClassDefFoundError:
org/apache/struts/legacy/GenericDataSource at
java.lang.ClassLoader.defineClass0(Native Method)
etc.

The versions I tried to find the DataSource (xml see below) out of
TestAction.java:
1)
dataSource = servlet.findDataSource("org.apache.struts.action.DATA_SOURCE");

DATA_SOURCE was the key easy-strus-editor generated- I changed it into
personDS - see DataSources- tags below.
After finding out method is deprecated tried with:
2)
dataSource = (DataSource)servlet.getServletContext().getAttribute("org.apache.struts.action.DATA_SOURCE");
3)
dataSource = (DataSource)servlet.getServletContext().getAttribute(Globals.DATA_SOURCE_KEY);
4)
dataSource = (DataSource)servlet.getServletContext().getAttribute("personDS");

I tried it also with genericDS - still the same error!

This are my DataSources:

<!-- ========== Data Source Configuration
=============================== -->
<data-sources>
<data-source type="org.apache.commons.dbcp.BasicDataSource"
key="personDS">
<set-property property="driverClassName"
value="org.gjt.mm.mysql.Driver" />
<set-property property="url"
value="jdbc:mysql://localhost/protokollDB" />
<set-property property="username" value="root" />
<set-property property="password" />
<set-property property="maxActive" value="10" />
<set-property property="maxWait" value="5000" />
<set-property property="defaultAutoCommit" value="false" />
<set-property property="defaultReadOnly" value="false" />
<set-property property="validationQuery" value="SELECT * FROM
Person" />
</data-source>
<data-source type="org.apache.struts.util.GenericDataSource"
key="genericDS">
<set-property property="autoCommit" value="false" />
<set-property property="description" value="Example Data Source
Conf"/>
<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" />
<set-property property="url"
value="jdbc:mysql://localhost/protokollDB" />
<set-property property="user" value="root" />
</data-source>
</data-sources>



I built the following files:

Interfaces:
myTable.java
myDB.java

actionBean:
TestAction.java

formBean:
TestForm.java

jsp:
testMyTable.jsp

struts-conf:

struts-conf-test.xml

whats wrong?
I would be very thankful for a hint.

thanks in advance

marcelino
 
S

Sudsy

marcelino said:
Hi,

still I'm a newbie handling struts. I tried to expand the
struts-example with a mysql DB-Connection called test. I can access
the example-welcome-site, but trying to activate the link to my site I
become this error:

ERROR: User database not loaded -- check servlet container logs for
error messages.
<snip>

There is a method in the Action class called getDataSource. It requires
an HttpServletRequest as an argument and will optionally accept a key.
RTFM for details.
 
K

KD

Hi

There is a file (struts-legacy.jar) that is missing from your tomcat lib.

-Karim

Hi,

still I'm a newbie handling struts. I tried to expand the
struts-example with a mysql DB-Connection called test. I can access
the example-welcome-site, but trying to activate the link to my site I
become this error:

ERROR: User database not loaded -- check servlet container logs for
error messages.

In the logs I find this two striking errors:

1)
2004-02-04 19:13:44 StandardContext[/test_struts]: Servlet
/test_struts threw load() exception
javax.servlet.ServletException: Servlet.init() for servlet action
threw exception at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:963)
etc.

2)
----- Root Cause -----
java.lang.NoClassDefFoundError:
org/apache/struts/legacy/GenericDataSource at
java.lang.ClassLoader.defineClass0(Native Method)
etc.

The versions I tried to find the DataSource (xml see below) out of
TestAction.java:
1)
dataSource = servlet.findDataSource("org.apache.struts.action.DATA_SOURCE");

DATA_SOURCE was the key easy-strus-editor generated- I changed it into
personDS - see DataSources- tags below.
After finding out method is deprecated tried with:
2)
dataSource = (DataSource)servlet.getServletContext().getAttribute("org.apache.struts.action.DATA_SOURCE");
3)
dataSource = (DataSource)servlet.getServletContext().getAttribute(Globals.DATA_SOURCE_KEY);
4)
dataSource = (DataSource)servlet.getServletContext().getAttribute("personDS");

I tried it also with genericDS - still the same error!

This are my DataSources:

<!-- ========== Data Source Configuration
=============================== -->
<data-sources>
<data-source type="org.apache.commons.dbcp.BasicDataSource"
key="personDS">
<set-property property="driverClassName"
value="org.gjt.mm.mysql.Driver" />
<set-property property="url"
value="jdbc:mysql://localhost/protokollDB" />
<set-property property="username" value="root" />
<set-property property="password" />
<set-property property="maxActive" value="10" />
<set-property property="maxWait" value="5000" />
<set-property property="defaultAutoCommit" value="false" />
<set-property property="defaultReadOnly" value="false" />
<set-property property="validationQuery" value="SELECT * FROM
Person" />
</data-source>
<data-source type="org.apache.struts.util.GenericDataSource"
key="genericDS">
<set-property property="autoCommit" value="false" />
<set-property property="description" value="Example Data Source
Conf"/>
<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" />
<set-property property="url"
value="jdbc:mysql://localhost/protokollDB" />
<set-property property="user" value="root" />
</data-source>
</data-sources>



I built the following files:

Interfaces:
myTable.java
myDB.java

actionBean:
TestAction.java

formBean:
TestForm.java

jsp:
testMyTable.jsp

struts-conf:

struts-conf-test.xml

whats wrong?
I would be very thankful for a hint.

thanks in advance

marcelino
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top