You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Daniel Mikusa <dm...@pivotal.io> on 2015/02/25 13:48:21 UTC
Re: Help setting up sqlite data source
On Wed, Feb 25, 2015 at 2:19 AM, nandy r <na...@yahoo.com.invalid>
wrote:
> Hello,
> I wanted to setup tomcat+hibernate+JOTM+sqlite but could not find any
> information on sqlite setup.
> I did read a document on setting up datasources and also one tomcat
> document relating to mysql, postgresql.
> It appears I need to supply a resource name, auth, factory, driver class
> and url, which could be:
> resource name- any name I want to supply
> auth-does this apply to sqlite????
>
Set this to `Container`.
> factory -whats the factory for sqlite???
>
Omit the `factory` attribute and you'll use the default. It's almost
certainly what you want. The factory attribute is used to specify a
different connection pool implementation. Using the default is OK, unless
you have a strong preference as to which implementation you use.
> driverclass-class of jdbc driver lib
>
This needs to be the name of the JDBC Driver class that you'll use. I
haven't used SQLite so I can't say what it would be. This is also one of
the few properties that are specific to your database of choice.
> url-connection string
>
This is the second commonly used property that will be specific to your
database. You'd need to look at the docs for the SQLite JDBC driver to see
what the URL should look like. Generally it'll start with "jdbc:...".
>
> So please let me know how to setup the sqlite database and if you have a
> working configuration that would be great!
>
1.) Download your JDBC driver. Put it into the "lib" directory of your
Tomcat server.
2.) Edit "conf/server.xml". Locate the <GlobalNamingResources> tag. Add a
new <Resource/> within this block. [1]
3.) Here's a minimal example, you just need to fill in the blanks. For
more options, see here [2].
<Resource name="jdbc/<your-jndi-name>"
auth="Container"
type="javax.sql.DataSource"
username="<your-db-user>"
password="<your-db-pass>"
driverClassName="<driver-class-name>"
url="jdbc:... " />
4.) Create a file in the `conf/Catalina/localhost/` directory with the same
name as your application, but with the ".xml" extension. For example, if
my WAR file is called `superCoolApp.war`. I'd create
`conf/Catalina/localhost/superCoolApp.xml`. This will store configuration
specific to your app. In that file, add the following. [3]
<Context>
<ResourceLink name="jdbc/<your-jndi-name>"
global="jdbc/<your-jndi-name>" type="javax.sql.DataSource" />
</Context>
This configuration will tell Tomcat that your app is allowed to use the
global Resource we defined above.
5.) Restart your Tomcat server. This will pick up the changes in
"conf/server.xml".
6.) In your application, use JNDI to retrieve a connect. Example of this
here [4].
You should also check out the docs here. While they're not specific to
your database, much of the information is still valid. Sections like the
"Preventing database connection pool leaks", "Common Problems" and the code
samples for accessing a db connection are not DB specific.
Dan
Alternatively, you can skip steps #2 & #3 above and just put the
<Resource/> tag directly into the `conf/Catalina/localhost` <Context/>
block, in place of the <ResourceLink/> tag. I prefer the steps above which
create a global, shared resource. This alternative creates a pool specific
to your app.
[1] -
http://tomcat.apache.org/tomcat-8.0-doc/jndi-resources-howto.html#Global_configuration
[2] - http://commons.apache.org/proper/commons-dbcp/configuration.html
[3] -
http://tomcat.apache.org/tomcat-8.0-doc/config/context.html#Resource_Links
[4] -
http://tomcat.apache.org/tomcat-8.0-doc/jndi-resources-howto.html#Using_resources
[5] -
http://tomcat.apache.org/tomcat-8.0-doc/jndi-datasource-examples-howto.html
> TIA,
> nandy
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
Re: Help setting up sqlite data source
Posted by nandy r <na...@yahoo.com.INVALID>.
dear Dan
Thanks a ton for the detailed info I will try it out in a couple of days. This email had got into my spam folder and I had missed it till today
rgds,
nandy
--------------------------------------------
On Wed, 2/25/15, Daniel Mikusa <dm...@pivotal.io> wrote:
Subject: Re: Help setting up sqlite data source
To: "Tomcat Users List" <us...@tomcat.apache.org>
Date: Wednesday, February 25, 2015, 4:48 AM
On Wed, Feb 25, 2015 at
2:19 AM, nandy r <na...@yahoo.com.invalid>
wrote:
>
Hello,
> I wanted to setup
tomcat+hibernate+JOTM+sqlite but could not find any
> information on sqlite setup.
> I did read a document on setting up
datasources and also one tomcat
>
document relating to mysql, postgresql.
>
It appears I need to supply a resource name, auth, factory,
driver class
> and url, which could
be:
> resource name- any name I want to
supply
> auth-does this apply to
sqlite????
>
Set this to `Container`.
> factory -whats the
factory for sqlite???
>
Omit the `factory` attribute
and you'll use the default. It's almost
certainly what you want. The factory
attribute is used to specify a
different
connection pool implementation. Using the default is OK,
unless
you have a strong preference as to
which implementation you use.
> driverclass-class of jdbc
driver lib
>
This needs to be the name of the JDBC Driver
class that you'll use. I
haven't used SQLite so I can't say what
it would be. This is also one of
the few
properties that are specific to your database of choice.
>
url-connection string
>
This is the second commonly
used property that will be specific to your
database. You'd need to look at the docs
for the SQLite JDBC driver to see
what the
URL should look like. Generally it'll start with
"jdbc:...".
>
> So please let me know
how to setup the sqlite database and if you have a
> working configuration that would be
great!
>
1.) Download your JDBC driver. Put it into
the "lib" directory of your
Tomcat
server.
2.) Edit
"conf/server.xml". Locate the
<GlobalNamingResources> tag. Add a
new <Resource/> within this block. [1]
3.) Here's a minimal example, you just need
to fill in the blanks. For
more options,
see here [2].
<Resource
name="jdbc/<your-jndi-name>"
auth="Container"
type="javax.sql.DataSource"
username="<your-db-user>"
password="<your-db-pass>"
driverClassName="<driver-class-name>"
url="jdbc:... " />
4.) Create a file in the
`conf/Catalina/localhost/` directory with the same
name as your application, but with the
".xml" extension. For example, if
my WAR file is called `superCoolApp.war`.
I'd create
`conf/Catalina/localhost/superCoolApp.xml`.
This will store configuration
specific to
your app. In that file, add the following. [3]
<Context>
<ResourceLink
name="jdbc/<your-jndi-name>"
global="jdbc/<your-jndi-name>"
type="javax.sql.DataSource" />
</Context>
This configuration will tell Tomcat that your
app is allowed to use the
global Resource we
defined above.
5.) Restart
your Tomcat server. This will pick up the changes in
"conf/server.xml".
6.) In your application, use
JNDI to retrieve a connect. Example of this
here [4].
You
should also check out the docs here. While they're not
specific to
your database, much of the
information is still valid. Sections like the
"Preventing database connection pool
leaks", "Common Problems" and the code
samples for accessing a db connection are not
DB specific.
Dan
Alternatively, you can skip
steps #2 & #3 above and just put the
<Resource/> tag directly into the
`conf/Catalina/localhost` <Context/>
block, in place of the <ResourceLink/>
tag. I prefer the steps above which
create
a global, shared resource. This alternative creates a pool
specific
to your app.
[1] -
http://tomcat.apache.org/tomcat-8.0-doc/jndi-resources-howto.html#Global_configuration
[2] - http://commons.apache.org/proper/commons-dbcp/configuration.html
[3] -
http://tomcat.apache.org/tomcat-8.0-doc/config/context.html#Resource_Links
[4] -
http://tomcat.apache.org/tomcat-8.0-doc/jndi-resources-howto.html#Using_resources
[5] -
http://tomcat.apache.org/tomcat-8.0-doc/jndi-datasource-examples-howto.html
> TIA,
>
nandy
>
>
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org