Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

datamining jndi connection

 
vasanthi naveen
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
iam getting the following error while connecting mysql with java for datamining.

java.lang.ClassCastException: org.apache.commons.dbcp.BasicDataSource

my code is:

test.jsp

html
head
title DB Test title
head
body

<%<br /> foo.MarketBasket tst = new foo.MarketBasket();<br /> tst.init();<br /> %>
</body>
</html>

MarketBasket.java

public void init()throws JDMException,NamingException, SQLException
{
Context ctx = new InitialContext();
System.out.println("after initial context");
javax.datamining.resource.ConnectionFactory jdmCFactory =
(ConnectionFactory) ctx.lookup("java:comp/env/jdbc/TestDB");
ConnectionSpec svrConnSpec = (javax.datamining.resource.ConnectionSpec)
jdmCFactory.getConnectionSpec();
System.out.println("got connection1");
svrConnSpec.setName( "username" );
svrConnSpec.setPassword( "password" );
svrConnSpec.setURI( "url" );
m_dmeConn = jdmCFactory.getConnection( svrConnSpec );
System.out.println("connection got");
}

server.xml

<Context path="/Databasemining" reloadable="true" docBase="D:\vasanthi\dataminingworkspace\Databasemining" workDir="D:\vasanthi\dataminingworkspace\Databasemining\work" >
< !--<Context path="/DBTest" docBase="DBTest"<br /> debug="5" reloadable="true" crossContext="true">-->



<Resource name="jdbc/TestDB"<br /> auth="Container"<br /> type="javax.sql.DataSource"/>

<ResourceParams name="jdbc/TestDB">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>

< !-- Maximum number of dB connections in pool. Make sure you<br /> configure your mysqld max_connections large enough to handle<br /> all of your db connections. Set to 0 for no limit.<br /> -->
<parameter>
<name>maxActive</name>
<value>100</value>
</parameter>

< !-- Maximum number of idle dB connections to retain in pool.<br /> Set to 0 for no limit.<br /> -->
<parameter>
<name>maxIdle</name>
<value>30</value>
</parameter>

< !-- Maximum time to wait for a dB connection to become available<br /> in ms, in this example 10 seconds. An Exception is thrown if<br /> this timeout is exceeded. Set to -1 to wait indefinitely.<br /> -->
<parameter>
<name>maxWait</name>
<value>10000</value>
</parameter>

< !-- MySQL dB username and password for dB connections -->
<parameter>
<name>username</name>
<value>root</value>
</parameter>
<parameter>
<name>password</name>
<value>root</value>
</parameter>

< !-- Class name for mm.mysql JDBC driver -->
<parameter>
<name>driverClassName</name>
<value>org.gjt.mm.mysql.Driver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:mysql://localhost:3306/javatest?autoReconnect=true</value>
</parameter>
</ResourceParams>
</Context>
what may be the possible fault.i have included all the jars ie commons.commons-dbcp-1.2.2,jdm jar,mysql jar and all.
its urgent.please reply for this request.thanks in advance.
 
ramya narayanan
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
where is my original topic here?
A layman's doubt on build
 
Paul Yule
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it ended up being moved to the Ant/Maven/Other build tools forum instead of where the link sent us. I don't know if the error can be fixed.

P.S. Vasanthi: Sorry for the hi-jack.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic