Trying to connect to a (local) SQL database using jTDS JDBC drivers.
JAVA CODE
private JtdsDataSource dataSource = null;
public Connection getConnection() throws SQLException, NamingException {
...
Context initContext = new InitialContext();
dataSource = (JtdsDataSource) initContext.lookup("java:comp/env/jdbc/postcodes");
conn = dataSource.getConnection();
...
}
CONTEXT.XML
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource name="jdbc/postcodes"
auth="Container"
type="javax.sql.DataSource"
username="user"
password="pass"
driverClassName="net.sourceforge.jtds.jdbcx.JtdsDataSource"
url="jdbc:jtds:sqlserver://localhost:1433/AUSPostcodes"
validationQuery="select 1"
maxActive="10"
maxIdle="4"/>
</Context>
When I run this on tomcat, get the following error....
java.lang.ClassCastException: org.apache.tomcat.dbcp.dbcp.BasicDataSource cannot be cast to net.sourceforge.jtds.jdbcx.JtdsDataSource
Would appreciate some help with this.
Thanks in advance.