Bug #1246 MysqlDataSourceFactory port paramter not optional
Submitted: 11 Sep 2003 6:00 Modified: 13 Jan 2004 13:33
Reporter: Klaus Halfmann Email Updates:
Status: Closed Impact on me:
Category:Connector / J Severity:S4 (Feature request)
Version:mysql-connector-java-3.0.8-stable OS:Microsoft Windows (WinXP)
Assigned to: CPU Architecture:Any
Triage: D5 (Feature request)

[11 Sep 2003 6:00] Klaus Halfmann
I tried to register MYSQL as dataSource with Tomcat in our server.xml 
using the following entries:
<Resource name="jdbc/tl-datasource" auth="Container"
	type="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" />
<ResourceParams name="jdbc/tl-datasource">

How to repeat:
Take a Vanilla tomcat jakarta-tomcat-4.1.24
put mysql-connector-java-3.0.8-stable-bin.jar
into the 'common/lib' directory
add the above to some context.

in some jsp page (or servlet or whatever) incldue the following code

      Context ctx = new InitialContext();
        if (ctx == null)
        DataSource ds =
            (DataSource) ctx.lookup("java:comp/env/jdbc/tl-datasource");

Tomcat will refuse to start up with 
        at org.apache.naming.NamingContext.lookup(NamingContext.java:844)
        at org.apache.naming.SelectorContext.lookup(SelectorContext.java:183)
        at javax.naming.InitialContext.lookup(InitialContext.java:347)

(One problem here is that tomcat silently swallows the exception originating
 from MysqlDataSourceFactory)

Suggested fix:
a) Fix: add the (not optional !) port parameter 

b) Change MysqlDataSourceFactory to make most parameters optional

int portNumber = 3306;
String sPortNumber = (String)ref.get("port").getContent();
if (sPortNumber != null)
    portNumber = Integer.parseInt(sPortNumber);
String serverName = (String)ref.get("serverName").getContent());
if (serverName != null)
String user = (String)ref.get("user").getContent());
if (user != null)

c) Document this behaviour more detailed :-( 
   (It took me 4 hours to figure out where the problem was)
[13 Jan 2004 13:33] Mark Matthews
Thank you for your bug report. This issue has already been fixed
in the latest released version of that product, which you can download at 

Additional info:

This was fixed in 3.0.9.