pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedConnection pooling in java
3+ messages / 3 participants
[nested] [flat]
* Connection pooling in java
@ 2006-12-22 08:02 janaka priyadarshana <rpjanaka@gmail.com>
2006-12-22 10:34 ` Re: Connection pooling in java Ido M. Tamir <tamir@imp.univie.ac.at>
2006-12-22 17:47 ` Re: Connection pooling in java Guy Rouillier <guyr-ml1@burntmail.com>
0 siblings, 2 replies; 3+ messages in thread
From: janaka priyadarshana @ 2006-12-22 08:02 UTC (permalink / raw)
To: pgsql-jdbc
hi all..
i am tring to use connection pool with postgresql..but it give an Exception
when it is going to execute the line following.
InitialContext().rebind("DataSource", source)
the cord is as follow.
Jdbc3PoolingDataSource source = new Jdbc3PoolingDataSource();
source.setDataSourceName("A Data Source");
source.setServerName("localhost");
source.setDatabaseName("mmsc");
source.setUser("janaka");
source.setPassword("1234");
source.setMaxConnections(10);
try {
new InitialContext().rebind("DataSource", source);
}
catch (NamingException ex) {
System.out.println(ex.getMessage());
ex.printStackTrace();
}
the given exception is as follow....
javax.naming.NoInitialContextException: Need to specify class name in
environment or system property, or as an applet parameter, or in an
application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java
:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java
:247)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(
InitialContext.java:284)
at javax.naming.InitialContext.rebind(InitialContext.java:367)
at MainClass.main(MainClass.java:29)
please help me to solve this..
--
...........Janaka Priyadarshana...........
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Connection pooling in java
2006-12-22 08:02 Connection pooling in java janaka priyadarshana <rpjanaka@gmail.com>
@ 2006-12-22 10:34 ` Ido M. Tamir <tamir@imp.univie.ac.at>
1 sibling, 0 replies; 3+ messages in thread
From: Ido M. Tamir @ 2006-12-22 10:34 UTC (permalink / raw)
To: pgsql-jdbc
On Friday 22 December 2006 09:02, janaka priyadarshana wrote:
http://www.mchange.com/projects/c3p0/index.html
c3p0 was designed to be butt-simple to use. Just put the jar file
[lib/c3p0-0.9.0.jar] in your application's effective CLASSPATH, and make a
DataSource like this:
import com.mchange.v2.c3p0.*;
...
ComboPooledDataSource cpds = new ComboPooledDataSource();
cpds.setDriverClass( "org.postgresql.Driver" ); //loads the jdbc driver
cpds.setJdbcUrl( "jdbc:postgresql://localhost/testdb" );
cpds.setUser("dbuser");
cpds.setPassword("dbpassword");
[Optional] If you want to turn on PreparedStatement pooling, you must also set
maxStatements and/or maxStatementsPerConnection(both default to 0):
cpds.setMaxStatements( 180 );
Do whatever you want with your DataSource, which will be backed by a
Connection pool set up with default parameters. You can bind the DataSource
to a JNDI name service, or use it directly, as you prefer.
When you are done, you can clean up the DataSource you've created like this:
DataSources.destroy( cpds );
That's it! The rest is detail.
hth
ido
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Connection pooling in java
2006-12-22 08:02 Connection pooling in java janaka priyadarshana <rpjanaka@gmail.com>
@ 2006-12-22 17:47 ` Guy Rouillier <guyr-ml1@burntmail.com>
1 sibling, 0 replies; 3+ messages in thread
From: Guy Rouillier @ 2006-12-22 17:47 UTC (permalink / raw)
To: pgsql-jdbc
janaka priyadarshana wrote:
> hi all..
>
> i am tring to use connection pool with postgresql..but it give an
> Exception when it is going to execute the line following.
> InitialContext().rebind("DataSource", source)
>
>
> the cord is as follow.
>
>
>
> Jdbc3PoolingDataSource source = new Jdbc3PoolingDataSource();
> source.setDataSourceName("A Data Source");
> source.setServerName("localhost");
> source.setDatabaseName("mmsc");
> source.setUser("janaka");
> source.setPassword("1234");
> source.setMaxConnections(10);
> try {
> new InitialContext().rebind("DataSource", source);
> }
> catch (NamingException ex) {
> System.out.println(ex.getMessage());
> ex.printStackTrace();
> }
>
>
>
>
> the given exception is as follow....
>
>
> javax.naming.NoInitialContextException : Need to specify class name in
> environment or system property, or as an applet parameter, or in an
> application resource file: java.naming.factory.initial
It's telling you what the problem is right there: you haven't supplied
sufficient information to construct an initial context. Specifically,
it wants you to tell it what class to use for java.naming.factory.initial.
What is your runtime platform? How you bind resources into JNDI is
determined by your runtime platform. Furthermore, many if not most
platforms provide a means to pool connections. Both JBoss and Tomcat
do, so constructing a pooled connection in those environments is as
simple as defining them in a configuration file, then looking them up in
your code.
--
Guy Rouillier
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2006-12-22 17:47 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-12-22 08:02 Connection pooling in java janaka priyadarshana <rpjanaka@gmail.com>
2006-12-22 10:34 ` Ido M. Tamir <tamir@imp.univie.ac.at>
2006-12-22 17:47 ` Guy Rouillier <guyr-ml1@burntmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox