I have been unable to access a database as suggested in
struts-example.war. I started with a working example that does not
access a database, and made a single change: I added a <datasource>
element to struts-config.xml. When I did that, the example at the first
attempt to access the action servlet.
Here's a relevant snippet from Tomcat's localhost_log:
...
2002-04-04 13:09:59 StandardWrapper[/testapp:action]: Marking servlet action as
unavailable
2002-04-04 13:09:59 StandardContext[/testapp]: Servlet /testapp threw load() exception
javax.servlet.UnavailableException: Initializing application data source
org.apache.struts.action.DATA_SOURCE
at
org.apache.struts.action.ActionServlet.initApplicationDataSources(ActionServlet.java:850)
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:419)
at javax.servlet.GenericServlet.init(GenericServlet.java:258)
...
I've tried both versions of the <datasources> element:
1. Section 4.4 of the Users Guide
<data-sources>
<data-source
autoCommit="false"
driverClass="org.postgresql.Driver"
maxCount="4"
minCount="2"
password="whatever"
url="jdbc:postgresql:mystraw"
user="postgres"
/>
</data-sources>
2. struts-example/WEB-INF/struts-config.xml version
<data-sources>
<data-source>
<set-property property="autoCommit" value="false"/>
<set-property property="driverClass"
value="org.postgresql.Driver"/>
<set-property property="maxCount" value="4"/>
<set-property property="minCount" value="2"/>
<set-property property="password" value="whatever"/>
<set-property property="url" value="jdbc:postgresql:mystraw"/>
<set-property property="user" value="postgres"/>
</data-source>
</data-sources>
To check that my setup is OK, I wrote the following class. It runs fine.
******
import java.sql.*;
import org.apache.struts.util.*;
public class Pgtest2 {
public static void main(String[] args) {
try {
// I believe this is what struts uses ...
GenericDataSource gds = new GenericDataSource();
// set all the properties from <datasource> element
gds.setAutoCommit(false);
gds.setDriverClass("org.postgresql.Driver");
gds.setMaxCount(2);
gds.setMinCount(4);
gds.setPassword("whatever");
gds.setUrl("jdbc:postgresql:mystraw");
gds.setUser("postgres");
// access database table and print to see whether it all works
Connection con = gds.getConnection();
Statement stm = con.createStatement();
stm.setQueryTimeout(10);
ResultSet rs = stm.executeQuery("select password from users");
rs.next();
System.out.println(rs.getString(1));
con.close();
} catch (Exception e) {
System.out.println("Exception!");
System.out.println(e.toString());
}
}
}
******
I'm using standalone Tomcat-4.0.2, Struts-1.1-b1, Postgresql-7.2.1 with
pgjdbc2.jar.
Any suggestions?
TIA,
--
Mark Johnson
[EMAIL PROTECTED]
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>