Hi Darren,
See below for some code that I recently sent to the list in relation to this problem. It helped with the other person, might work for you too.
Regards,
Martin


------
// fragment from web.xml
<resource-ref>
  <description>DB Connection</description>
  <res-ref-name>jdbc/dbname</res-ref-name>
  <res-type>javax.sql.DataSource</res-type>
  <res-auth>Container</res-auth>
</resource-ref>


// context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/contextname">
<Logger className="org.apache.catalina.logger.FileLogger" prefix="contextname." suffix=".log" timestamp="true"/> <Resource auth="Container" driverClassName="com.mysql.jdbc.Driver" factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory" maxActive="30" maxIdle="10" maxWait="10000" name="jdbc/dbname" password="******" removeAbandoned="true" removeAbandonedTimeout="60" type="javax.sql.DataSource" url="jdbc:mysql://localhost:3306/database" username="user"/>
</Context>


// sample servlet
public class myservlet extends HttpServlet {
private static DataSource ds=null; public void init(ServletConfig config) throws ServletException {
      try
      {
          Context ctx = new InitialContext();
          this.ds = (DataSource)ctx.lookup("java:comp/env/jdbc/dbname");
      }
      catch (Exception e) { e.printStackTrace(); }
      super.init(config);          }
        public void destroy() {
      ds=null;
  }
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException {
      response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter(); Connection connection=null;
      try
      {
connection=ds.getConnection(); Statement statement = connection.createStatement();
  // execute queries here...
          statement.close();
          connection.close();
      }
      catch(Exception e) { out.println(e.getMessage()); }
      finally { try{connection.close(); } catch(Exception e) {} }
      out.close();      }
}


Darren Hall wrote:
Have you tried
username="myuserid" password="mypassword"
instead  username="(myuserid)" password="(mypassword)"

Yes Jean-Claude. In fact, I don't use the parenthesis around the username
and password in my context.xml file. I just listed it that way here in the
list so people would understand the content was changed from the way it
actually appeared in my context.xml. Looking back now, perhaps not such a
good idea, huh?

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





--
------------
Martin Grogan
Keizen Software

[EMAIL PROTECTED]
www.keizensoftware.com


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to