Return-Path: Delivered-To: apmail-tomcat-users-archive@www.apache.org Received: (qmail 57076 invoked from network); 10 Nov 2005 22:06:33 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 10 Nov 2005 22:06:33 -0000 Received: (qmail 13247 invoked by uid 500); 10 Nov 2005 22:06:17 -0000 Delivered-To: apmail-tomcat-users-archive@tomcat.apache.org Received: (qmail 13233 invoked by uid 500); 10 Nov 2005 22:06:17 -0000 Mailing-List: contact users-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Users List" Delivered-To: mailing list users@tomcat.apache.org Received: (qmail 13222 invoked by uid 99); 10 Nov 2005 22:06:17 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Nov 2005 14:06:17 -0800 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [204.13.168.240] (HELO m16.webhostfreaks.com) (204.13.168.240) by apache.org (qpsmtpd/0.29) with SMTP; Thu, 10 Nov 2005 14:06:10 -0800 Received: (qmail 18880 invoked by uid 0); 10 Nov 2005 17:05:55 -0500 Received: from ben@benslade.com by m16.webhostfreaks.com by uid 509 with qmail-scanner-1.22-st-qms ( Clear:RC:1(204.13.168.150):SA:0(0.0/3.0):. Processed in 6.053243 secs); 10 Nov 2005 22:05:55 -0000 X-Antivirus-`hostname`-Mail-From: ben@benslade.com via m16.webhostfreaks.com X-Antivirus-`hostname`: 1.22-st-qms (Clear:RC:1(204.13.168.150):SA:0(0.0/3.0):. Processed in 6.053243 secs Process 18874) Received: from unknown (HELO lithium.webhostfreaks.com) (204.13.168.150) by m16.webhostfreaks.com with SMTP; 10 Nov 2005 22:05:49 -0000 Received: from pool-70-21-93-146.res.east.verizon.net ([70.21.93.146] helo=[192.168.1.100]) by lithium.webhostfreaks.com with esmtpa (Exim 4.52) id 1EaKYF-0002cE-DI; Thu, 10 Nov 2005 17:05:47 -0500 Message-ID: <4373C439.3000307@benslade.com> Date: Thu, 10 Nov 2005 17:05:45 -0500 From: Benjamin Slade User-Agent: Thunderbird 1.4 (Macintosh/20050908) MIME-Version: 1.0 To: users@tomcat.apache.org CC: andre@toly.nl Subject: Re: Pointers on setting up Tomcat w/MySQL on OS X? Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-PopBeforeSMTPSenders: ben@benslade.com X-Virus-Checked: Checked by ClamAV on apache.org X-Old-Spam-Status: No, hits=0.0 required=3.0 X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Thanks for the info. I have a few questions which are embedded below: Andr� van Toly wrote: > Hi, > > Op 9-nov-2005, om 23:07 heeft Benjamin Slade het volgende geschreven: >> Can someone point me to some resources for setting up Tomcat so that >> servlets/JSP's can connect to a local MySQL database? >> >> The instructions for configuring Connector/J don't seem to match the >> setup of my tomcat/conf/server.xml file. Specifically, the >> Connector/J web page talks about adding: >> Inside the tag of the conf/server.xml file, but there is no >> tag in my conf/server.xml. Should I add one? Or should I >> add these XML tags to the tomcat/conf/context.xml? Where can I find >> documentation on the structure of the server.xml and context.xml >> files? The Apache Tomcat Configuration Reference web page doesn't >> have much and neither does the Database question in the Tomcat FAQ. > Yes, you need to add a context to your [tomcat]/conf/server.xml. For > example for Tomcat's ROOT context the configuration could look like: > > > name="jdbc/TestDB > auth="Container" > type="javax.sql.DataSource" > maxActive="100" > maxIdle="30" > maxWait="10000" > username="username" > password="password" > driverClassName="com.mysql.jdbc.Driver" > url="jdbc:mysql://localhost:3306/databasename?autoReconnect=true" > /> > > > The ROOT context is the webapp called ROOT :-) which we'll be at > http://localhost:8080 For the tag above: Using the docBase of "ROOT" is only when placing servlets into a single ROOT directory, right? I'd prefer to set things up with a servlet/JSP in it's own web application directory, because that's how most app's run in real life. So instead, I'm going to leave out the path="" docBase="ROOT" and I'm going to put the tag into my $CATALINA_HOME/webapps//MyApps//WEB-INF/web.xml file, near the end (where /MyApps/ is the directory for my test servlet/JSP). Is this correct, will it work? (The answer seems to be "no". See below) On the other hand, if I wanted to add the above tag to my server.xml, where do I add it in the file? The web page http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html says: > Add this in between the || tag of the examples context and > the || tag closing the localhost definition. If there is no > such tag, you can add one as illustrated in the Context > (http://tomcat.apache.org/tomcat-5.5-doc/config/context.html) and Host > (http://tomcat.apache.org/tomcat-5.5-doc/config/host.html) > configuration references, and repeated below for your convenience. Both of those web pages are involved architecture reference pages, so unless I hear from someone else on this mailing list, I'll spend the next few hours wading through them. > > Your webapp configuration [tomcat]/webapps/ROOT/WEB-INF/web.xml should > have a reference to the resource and in this example has to look like > this: > > > DB Connection > jdbc/TestDB > javax.sql.DataSource > Container > > > Now you can try the example at point 4. of the 'MySQL DBCP Example': > http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html > > > Remember to install the taglib's the example requires. And you should > of course have a MySQL jdbc driver (f.e. > mysql-connector-java-3.1.10-bin.jar) installed in [tomcat]/common/lib. I haven't used taglibs before so I'll have to figure out how to install them. In the meantime, I tried running the servlet: > <% > DataSource ds=null; > Context ctx = new InitialContext(); > if(ctx == null ) > throw new Exception("Boom - No Context"); > ds=(DataSource)ctx.lookup("java:comp/env/jdbc/TestDB"); > if(ds == null ) > throw new Exception("Boom - No Datasource"); > > Connection conn=ds.getConnection(); > Statement stmt=conn.createStatement(); > ResultSet rs=stmt.executeQuery("select 'Hello World'"); > if (rs.next()){ > %><%=rs.getString(1)%><% > } > %> But I get the error "Cannot create JDBC driver of class '' for connect URL 'null'" apparently resulting from the ds.getConnection() call. > Success. > > ---Andr� > The Apache Tomcat Configuration Reference: The Context Container web > page seems to have lots of information, but it seems like a lot of > reference detail. I just need a database "Hello World" example. > > I'm a newbie so I'm not familiar with the structure/semantics of the > server.xml and context.xml files. Also, I haven't gotten around to > learning how JNDI works. I was sort of hoping to do a "Hello World" > database JSP before delving into all of the system guts. > > Thanks > Ben Slade --Andr� van Toly web http://www.toly.nl mobile +31(0)627233562 ------------------------------------------------------------------>><<-- --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org For additional commands, e-mail: users-help@tomcat.apache.org