Hi Folks,
 
For those of you with ten minutes to spare, please read on.
 
I'm having trouble with my database test app. As a background, I'm writing my Action and ActionForm classes in Visual Age for Java, then exporting my classes to the WEB-INF\classes directory of my application. Within the lib directory I include struts.jar and the jdbc thin drivers in .zip format (if these are not needed here please tell me).
 
I have tried to run this two ways. The first was using the datasource tag in the struts-config.xml file. I included it right after my action-mappings and form-beans tag, all of which are included inside the struts-config tags. When I start my Tomcat server, I receive an error in the console that says basically that there are illegal characters after my action-mapping tag ends (I.e. the datasource tag). The console will also give me a class not found exception at java.sql.Datasource. After I point my browser at the war file I get an error stating that it can't find the ActionMappings or ActionFormBeans collection.
 
The second way I tried to run this was by simply establishing a connection to the database manually in my Action class and using Class.forName(jdbcUrl). However, this time, when I try run the app it will crap out when I try to do the actual query and give me a class not found exception at Class.forName(jdbcUrl) at the Tomcat console. The browser gives me a null pointer exception. I think I have all the required imports within my classes.
 
Using the datasource tag looks like it should be very straight forward but I'm having no joy. For anyone who has read this far, I apologize for the length of the message. I have included my code from the struts-config.xml file and my Action class perform() method.
 
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
   "-//Apache Software Foundation//DTD Struts Configuration 1.0//EN"
   "http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd">
<struts-config>
   
   <form-beans>
      <form-bean name="databaseForm"
      type="dbtest.DatabaseForm"/>
    </form-beans>
   
    <action-mappings>
      <action path="/dbtest"
      type="dbtest.DatabaseAction"
       name="databaseForm">
                   
      <forward name="success" path="/success.jsp" />
   <forward name="fail" path="/fail.jsp" />
  
   </action>
 </action-mappings>
 <data-sources>
       <data-source
         key="dbtest"
          autoCommit="false"
          description="Database Test"
          driverClass="oracle.jdbc.driver.OracleDriver"
            maxCount="4"
            minCount="2"
            password="password"
             url="jdbc:oracle:thin:@servername:1521:XXXX"
             user="username"
   />
   </data-sources>
  
</struts-config>
 
public ActionForward perform(
 ActionMapping mapping,
 ActionForm form,
 HttpServletRequest request,
 HttpServletResponse response)
 throws javax.servlet.ServletException, java.io.IOException {
 
 //String jdbcDriver = "oracle.jdbc.driver.OracleDriver";
 //String jdbcUrl = "jdbc:oracle:thin:@servername:1521:XXXX";
 java.sql.Connection myConnection = null;
 
 DatabaseForm theForm = (DatabaseForm) form;
 
 String id = theForm.getPackage_id();
 
 String description =null;
 java.sql.ResultSet rs = null;
 try
 {
  javax.sql.DataSource dataSource = servlet.findDataSource("dbtest");
   myConnection = dataSource.getConnection();
  System.out.println("You are here #1");
  //Class.forName(jdbcDriver);
  //System.out.println("You are here #2");
  //myConnection = java.sql.DriverManager.getConnection(jdbcUrl);
  myConnection = dataSource.getConnection();
   java.sql.PreparedStatement stmt =
   myConnection.prepareStatement(
    "Select package_description From Packages Where package_id=" + id);
  
   rs = stmt.executeQuery();
  
  if (rs.next())
  {
   description = rs.getString("Package_Description");
  }
  else
  {
   description = "Empty";
  }
  
  theForm.setPackage_description(description);
  
 
 }
 
 catch (java.sql.SQLException sqle)
 {
  getServlet().log("Connection.process", sqle);
 }
 //catch (ClassNotFoundException e)
 //{
 //}
 catch (NullPointerException npe)
 {
  
 }
 finally
 {
 
  try
  {
 
   myConnection.close();
  }
  catch (java.sql.SQLException e)
  {
   getServlet().log("Connection.close", e);
  }
 }
 //if (description != null)
 //{
  return mapping.findForward("success");
 //}
 //else
 //{
  //return mapping.findForward("fail");
 //}
 
}
 
Any help is greatly appreciated,
 
Scott Fitzgerald

Reply via email to