tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Neven Cvetkovic <neven.cvetko...@gmail.com>
Subject Re: Trouble loading MS SQl Server database driver in Tomcat 7.0.37
Date Tue, 02 Apr 2013 16:44:26 GMT
David

My bad, I gave you the wrong code for testing database connections. I was
just typing the code from my head, I did not test it myself. I probably
should have used Eclipse before I gave you the code ;)

Here's a better version:

...
<%
    javax.naming.InitialContext naming = null;
    *java.sql.Connection* connection = null;
    *javax.sql.DataSource datasource = null;*
    try {
        naming = new javax.naming.InitialContext();
        datasource = (*javax.sql.DataSource*)
naming.lookup("java:comp/env/jdbc/smswebdb");
        connection = datasource.getConnection();
        connection.close();
        out.println("Connection has successfully obtained from datasource.
connection=" + connection);
    } catch (javax.naming.NamingException ne) {
        ne.printStackTrace();
        out.println("Datasource is not bound to JNDI: " + ne);
    } catch (*java.sql.SQLException* sqle) {
        sqle.printStackTrace();
        out.println("Problem with a SQL connection: " + sqle);
    } catch (Exception e) {
        e.printStackTrace();
        out.println("Something else went wrong: " + e);
    }
%>
...


So the correct classes are:
java.sql.Connection, java.sql.SQLException, javax.sql.DataSource (thanks
Dan)

Again, this is probably a very dirty way to test database connection pools
(datasources) managed by your Tomcat, and it just helps you troubleshoot
your connection setup.


About your second issue (unrelated) - Dan had a great question - check
where your *com.systemsmadesimple.hibernate.HibernateUtil* class is
deployed. This is a class that your developers wrote, and probably resides
in SystemsMadeSimple.war/WEB-INF/classes/com/systemsmadesimple/hibernate/Hibernate.class,
unless packaged as JAR.

Also, check that you have the Hibernate jar files as well. JBoss (I assume
you are migrating from JBoss 5.x) probably has Hibernate libraries
included, Tomcat does not, your application needs to pack these libraries.
All application-packaged third-party libraries (or your application shared
libraries) should reside in SystemsMadeSimple.war/WEB-INF/lib
directory. Although,
I think your previous console output showed that your Hibernate code was
being parsed, so Hibernate jars are probably packaged properly.

Cheers!

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message