mahout-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Mühlbachler <>
Subject Re: Taste-Web MySQLDataModel recommender example needed!
Date Wed, 16 Feb 2011 15:36:01 GMT
OK, so I must deploy my container a ressource file where all needed data 
is specified to connect to my MySQL server/database. Then I make a 
dataSource with an abstract type DataSource which is fetched via JNDI 
from my ressource file (I don't know which type it has - e.g. 
MySQL/PostgreSQL/... because I'm using an abstract type). This 
dataSource is given to my constructor and it should work? (so, it's 
something like a "workaround" :D )
In fact, I can use the Maven Jetty WebServer too if am able to deploy a 
valid ressource file and can include the MySQL Connector/J or I can make 
mvn package in the taste-web folder and copy the war file to an other 
container (e.g. Tomcat) to work with this file.

Am 16.02.2011 16:27, schrieb Sean Owen:
> You do not need to use the Connector/J classes directly, and shouldn't.
> Yes, you need a DataSource. If you're inside a web container, then you
> can and should already have configured the database connection in the
> container's configuration file. It makes the DataSource available for
> lookup via JNDI.
> At no point do you need to know that the DataSource is actually a
> MysqlDataSource in your code, no.
> I think you need to read that Tomcat page and understand how J2EE
> containers deal with DataSources via JNDI. It will be clearer. This is
> not specific to Mahout.
> 2011/2/16 Daniel Mühlbachler<>:
>> yeah, that's what I meant. My problem is that I am importing the MySQL
>> Connector/J directly in my source file.
>> So all my source files are not allowed to use such a class? But the
>> MySQLJDBCDataModel has a constructor like ...(DataSource ds, ...) and
>> DataSource is provided by the MySQL Connector/J but how can I give my
>> constructor a dataSource if I can't use the classes I need - deps that
>> shouldn't be there?
>> Moreover, if I can configure the jetty server that it can handle MySQL
>> connections it's also ok but how can I compile a java source file that needs
>> a dataSource which is declared in a class I can't use directly? (something
>> paradox...)
>> Am 16.02.2011 16:13, schrieb Sean Owen:
>>> No. As I've said, you never import the driver / connector classes
>>> directly. You have a complete working example: Mahout. As you can see
>>> it doesn't depend on this.
>>> As I've also said, please read the documentation for Tomcat (or your
>>> container). Here you go:
>>> This is where MySQL Connector/J is involved.
>>> 2011/2/16 Daniel Mühlbachler<>:
>>>> ok, thanks for your detailed answer - now I understand! :)
>>>> So my problem is that I must import the MySQL Connector/J into my source
>>>> files because I need them. The nasty thing about that is that I just need
>>>> "import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;" in my dataSource
>>>> but
>>>> that won't work because there shouldn't be any dependencies on that
>>>> because
>>>> I must configure the web application to use/provide the connector.
>>>> omg... Is there any example round here that shows such a configuration?

View raw message