Man this has been a while since I've reached out to this list, but here it
goes.

I am using Tomcat 7 on Windows 7 64x and trying to configure a datasource
(MySQL DB running on a 2nd box) to use.  I am able to connect from my local
to the remote using the mysql command line, so I do know the database is
reachable.  I have a vanilla server.xml and I'm putting the configuration
in the context.xml.  I've written a class to initialize connection objects
from the datasource.  After this configuration, I did something that I
never do and is bad form, but I wrote a jsp that used the <sql> jstl to do
a test to the database, and it worked, so I thought perfect, the JNDI
lookup must be correct.  Once I switched it over to only be used by the
backend code, I get a SQLException being thrown that says:

DataSource invalid: "java.sql.SQLException: No suitable driver found for
jdbc/dashboard"

While I am not 100% convinced that I need the <ResourceLink> tag in the
context.xml, but it's been pointed out multiple times that it is needed.
 Is there something that I am missing here?  Any advice or help you could
provide would be greatly appreciated.  I do think it's a configuration
issue, but I've been known to be wrong before.

Here is the snippet from my web.xml -

 <resource-ref>
      <description>DB Connection</description>
      <res-ref-name>jdbc/dashboard</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
  </resource-ref>

Here is my context.xml -

      <ResourceLink type="javax.sql.DataSource" name="jdbc/dashboard"
global="jdbc/DB" />

      <Resource name="jdbc/dashboard" auth="Container"
type="javax.sql.DataSource"
               maxActive="100" maxIdle="30" maxWait="10000"
               username="p05jg" password="testing"
driverClassName="com.mysql.jdbc.Driver"
               url="jdbc:mysql://10.0.48.14:3306/dashboard"
               poolPreparedStatments="true"
               maxOpenPreparedStatements="200"
               removeAbandoned="true" logAbandoned="true"
removeAbaondonedTimeout="300"/>

Here is my method for connection initialization -

 private static Logger logger =
LoggerFactory.getLogger("ConnectionInitializer.class"); private static
final String dbName = "jdbc/DB"; private static final String envName =
"java:/comp/env";

        public static Connection initialize () {

Connection connect = null;
 Context context;
try {
context = new InitialContext();
 DataSource dataSource = (DataSource)context.lookup(dbName);
connect = dataSource.getConnection();
 logger.debug("Connection returns schema: " + connect.getSchema());
} catch (NamingException nEx) {
 logger.error("initialize threw a NamingException:  ", nEx.getMessage());
nEx.printStackTrace();
 return null;
} catch (SQLException sqlEx) {
logger.error("initialize threw a SQLException:  ", sqlEx.getMessage());
 sqlEx.printStackTrace();
return null;
}
 return connect;
}

I have also tried another method for returning a connection object (same
method, just modified)

public static Connection initialize () {

Connection connect = null;
 Context initContext;
Context envContext;
try {
 initContext = new InitialContext();
envContext = (Context)initContext.lookup(dbName);
DataSource dataSource = (DataSource)envContext.lookup(envName + "/" +
dbName);
 connect = dataSource.getConnection();
logger.debug("Connection returns schema: " + connect.getSchema());
 } catch (NamingException nEx) {
logger.error("Uh-oh! - initializeConnection threw a NamingException:  ",
nEx.getMessage());
 logger.error("{} not found!", dbName);
nEx.printStackTrace();
return null;
 } catch (SQLException sqlEx) {
logger.error("Uh-oh - initializeConnection threw a SQLException:  ",
sqlEx.getMessage());
 sqlEx.printStackTrace();
return null;
}
 return connect;
}

Reply via email to