Skip to main content

JDBC Connection using SLEE archiecture...

5 replies [Last post]
mailtoseelan
Offline
Joined: 2007-03-11

HI,

Can any one please give me an idea about how to develope jdbc connectivity in Resource adaptor based on JSLEE architecture?

I want to use JDBC for PostgreSQL on Linux system...

I have one DataBase in postgresal "xxxx"..

How to i access the database from Mobicent?

This is my code i used...

xxxsbb.java,

Context ctx = (Context) new InitialContext();
DataSource ds = (DataSource)ctx.lookup("java:PostgreSQL");

sbb-jar.xml,

I added these lines,

DB Connection
jdbc/PostgreSQL
javax.sql.DataSource
Container

Also i created one PostgreSQL-ds.xml file on deploy folder of JBOSS server...

While executing in sbb.java file throws some exception

"java.lang.ClassCastException: org.jboss.resource.adapter.jdbc.WrapperDataSource"

Waiting for your reply...

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
baranowb
Offline
Joined: 2006-01-09

is data source correctly configured?

mailtoseelan
Offline
Joined: 2007-03-11

Hi,

Thanks for your reply..

I Solved the problem.

Riht now am directly connects the database from Sbb.java file..

Is it right way to do? or i have to follow the SLEE Architecture?

Can you please give me an idea about how to connect database via Resource adapter in mobicent?

alexandrem
Offline
Joined: 2005-10-19

Hi,

Yes, there's no problem in accessing DB directly from SBB.. it's kind of an exception to SLEE principles, as it is admitted that the access to DB is fast (mostly, using in-memory DBs) and won't block the sbb for a long time.

Alexandre Mendonca
JBoss R&D

mailtoseelan
Offline
Joined: 2007-03-11

Hi,

Thank U Alex....

mailtoseelan
Offline
Joined: 2007-03-11

Context ctx = (Context) new InitialContext();
DataSource ds = (DataSource)ctx.lookup("java:PostgreSQL");

Those 2 lines works fine now...

While going to the next line,

conn = ds.getConnection();

I got these errors...

15:22:18,421 WARN [JBossManagedConnectionPool] Throwable while attempting to ge
t a new connection: null
org.jboss.resource.JBossResourceException: Could not create connection; - nested
throwable: (org.postgresql.util.PSQLException: Connection refused. Check that t
he hostname and port are correct and that the postmaster is accepting TCP/IP con
nections.)
at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.c
reateManagedConnection(LocalManagedConnectionFactory.java:190)
at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.cr
eateConnectionEventListener(InternalManagedConnectionPool.java:619)
at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.ge
tConnection(InternalManagedConnectionPool.java:264)
at org.jboss.resource.connectionmanager.JBossManagedConnectionPool$BaseP
ool.getConnection(JBossManagedConnectionPool.java:613)
at org.jboss.resource.connectionmanager.BaseConnectionManager2.getManage
dConnection(BaseConnectionManager2.java:347)
at org.jboss.resource.connectionmanager.TxConnectionManager.getManagedCo
nnection(TxConnectionManager.java:330)
at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateC
onnection(BaseConnectionManager2.java:402)
at org.jboss.resource.connectionmanager.BaseConnectionManager2$Connectio
nManagerProxy.allocateConnection(BaseConnectionManager2.java:849)
at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(Wrapp
erDataSource.java:89)
at org.mobicents.slee.service.httpclientra.example.HttpClientRAExampleSb
b.onTimerEvent(HttpClientRAExampleSbb.java:330)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.mobicents.slee.runtime.sbbentity.SbbEntity.invokeEventHandler(Sbb
Entity.java:871)
at org.mobicents.slee.runtime.EventRouterImpl.routeQueuedEvent(EventRout
erImpl.java:892)
at org.mobicents.slee.runtime.EventRouterImpl.access$100(EventRouterImpl
.java:64)
at org.mobicents.slee.runtime.EventRouterImpl$EventExecutor.run(EventRou
terImpl.java:121)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExec
utor.java:650)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
.java:675)
at java.lang.Thread.run(Thread.java:595)
Caused by: org.postgresql.util.PSQLException: Connection refused. Check that the
hostname and port are correct and that the postmaster is accepting TCP/IP conne
ctions.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(Conne
ctionFactoryImpl.java:123)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactor
y.java:66)
at org.postgresql.jdbc2.AbstractJdbc2Connection.(AbstractJdbc2Conn
ection.java:124)
at org.postgresql.jdbc3.AbstractJdbc3Connection.(AbstractJdbc3Conn
ection.java:30)
at org.postgresql.jdbc3.Jdbc3Connection.(Jdbc3Connection.java:24)
at org.postgresql.Driver.makeConnection(Driver.java:386)
at org.postgresql.Driver.connect(Driver.java:260)
at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.c
reateManagedConnection(LocalManagedConnectionFactory.java:172)
... 20 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:520)
at java.net.Socket.connect(Socket.java:470)
at java.net.Socket.(Socket.java:367)
at java.net.Socket.(Socket.java:180)
at org.postgresql.core.PGStream.(PGStream.java:62)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(Conne
ctionFactoryImpl.java:77)
... 27 more
15:22:18,421 INFO [HttpClientRAExampleSbb] Could not set SBB context:org.jboss.
util.NestedSQLException: Could not create connection; - nested throwable: (org.p
ostgresql.util.PSQLException: Connection refused. Check that the hostname and po
rt are correct and that the postmaster is accepting TCP/IP connections.); - nest
ed throwable: (org.jboss.resource.JBossResourceException: Could not create conne
ction; - nested throwable: (org.postgresql.util.PSQLException: Connection refuse
d. Check that the hostname and port are correct and that the postmaster is accep
ting TCP/IP connections.))
15:22:18,437 ERROR [STDERR] org.jboss.util.NestedSQLException: Could not create
connection; - nested throwable: (org.postgresql.util.PSQLException: Connection r
efused. Check that the hostname and port are correct and that the postmaster is
accepting TCP/IP connections.); - nested throwable: (org.jboss.resource.JBossRes
ourceException: Could not create connection; - nested throwable: (org.postgresql
.util.PSQLException: Connection refused. Check that the hostname and port are co
rrect and that the postmaster is accepting TCP/IP connections.))
15:22:18,531 ERROR [STDERR] at org.jboss.resource.adapter.jdbc.WrapperDataSo
urce.getConnection(WrapperDataSource.java:95)
15:22:18,531 ERROR [STDERR] at org.mobicents.slee.service.httpclientra.examp
le.HttpClientRAExampleSbb.onTimerEvent(HttpClientRAExampleSbb.java:330)
15:22:18,531 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(
Native Method)
15:22:18,531 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(N
ativeMethodAccessorImpl.java:39)
15:22:18,531 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invo
ke(DelegatingMethodAccessorImpl.java:25)
15:22:18,531 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:5
85)
15:22:18,531 ERROR [STDERR] at org.mobicents.slee.runtime.sbbentity.SbbEntit
y.invokeEventHandler(SbbEntity.java:871)
15:22:18,531 ERROR [STDERR] at org.mobicents.slee.runtime.EventRouterImpl.ro
uteQueuedEvent(EventRouterImpl.java:892)
15:22:18,531 ERROR [STDERR] at org.mobicents.slee.runtime.EventRouterImpl.ac
cess$100(EventRouterImpl.java:64)
15:22:18,531 ERROR [STDERR] at org.mobicents.slee.runtime.EventRouterImpl$Ev
entExecutor.run(EventRouterImpl.java:121)
15:22:18,531 ERROR [STDERR] at java.util.concurrent.ThreadPoolExecutor$Worke
r.runTask(ThreadPoolExecutor.java:650)
15:22:18,531 ERROR [STDERR] at java.util.concurrent.ThreadPoolExecutor$Worke
r.run(ThreadPoolExecutor.java:675)
15:22:18,546 ERROR [STDERR] at java.lang.Thread.run(Thread.java:595)
15:22:18,546 ERROR [STDERR] Caused by: org.jboss.resource.JBossResourceException
: Could not create connection; - nested throwable: (org.postgresql.util.PSQLExce
ption: Connection refused. Check that the hostname and port are correct and that
the postmaster is accepting TCP/IP connections.)
15:22:18,546 ERROR [STDERR] at org.jboss.resource.adapter.jdbc.local.LocalMa
nagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.jav
a:190)
15:22:18,546 ERROR [STDERR] at org.jboss.resource.connectionmanager.Internal
ManagedConnectionPool.createConnectionEventListener(InternalManagedConnectionPoo
l.java:619)
15:22:18,546 ERROR [STDERR] at org.jboss.resource.connectionmanager.Internal
ManagedConnectionPool.getConnection(InternalManagedConnectionPool.java:264)
15:22:18,546 ERROR [STDERR] at org.jboss.resource.connectionmanager.JBossMan
agedConnectionPool$BasePool.getConnection(JBossManagedConnectionPool.java:613)
15:22:18,640 ERROR [STDERR] at org.jboss.resource.connectionmanager.BaseConn
ectionManager2.getManagedConnection(BaseConnectionManager2.java:347)
15:22:18,640 ERROR [STDERR] at org.jboss.resource.connectionmanager.TxConnec
tionManager.getManagedConnection(TxConnectionManager.java:330)
15:22:18,640 ERROR [STDERR] at org.jboss.resource.connectionmanager.BaseConn
ectionManager2.allocateConnection(BaseConnectionManager2.java:402)
15:22:18,640 ERROR [STDERR] at org.jboss.resource.connectionmanager.BaseConn
ectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.
java:849)
15:22:18,640 ERROR [STDERR] at org.jboss.resource.adapter.jdbc.WrapperDataSo
urce.getConnection(WrapperDataSource.java:89)
15:22:18,640 ERROR [STDERR] ... 12 more
15:22:18,640 ERROR [STDERR] Caused by: org.postgresql.util.PSQLException: Connec
tion refused. Check that the hostname and port are correct and that the postmast
er is accepting TCP/IP connections.
15:22:18,640 ERROR [STDERR] at org.postgresql.core.v3.ConnectionFactoryImpl.
openConnectionImpl(ConnectionFactoryImpl.java:123)
15:22:18,640 ERROR [STDERR] at org.postgresql.core.ConnectionFactory.openCon
nection(ConnectionFactory.java:66)
15:22:18,640 ERROR [STDERR] at org.postgresql.jdbc2.AbstractJdbc2Connection.
(AbstractJdbc2Connection.java:124)
15:22:18,640 ERROR [STDERR] at org.postgresql.jdbc3.AbstractJdbc3Connection.
(AbstractJdbc3Connection.java:30)
15:22:18,640 ERROR [STDERR] at org.postgresql.jdbc3.Jdbc3Connection.(J
dbc3Connection.java:24)
15:22:18,640 ERROR [STDERR] at org.postgresql.Driver.makeConnection(Driver.j
ava:386)
15:22:18,640 ERROR [STDERR] at org.postgresql.Driver.connect(Driver.java:260
)
15:22:18,640 ERROR [STDERR] at org.jboss.resource.adapter.jdbc.local.LocalMa
nagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.jav
a:172)
15:22:18,640 ERROR [STDERR] ... 20 more
15:22:18,640 ERROR [STDERR] Caused by: java.net.ConnectException: Connection ref
used: connect
15:22:18,640 ERROR [STDERR] at java.net.PlainSocketImpl.socketConnect(Native
Method)
15:22:18,640 ERROR [STDERR] at java.net.PlainSocketImpl.doConnect(PlainSocke
tImpl.java:333)
15:22:18,656 ERROR [STDERR] at java.net.PlainSocketImpl.connectToAddress(Pla
inSocketImpl.java:195)
15:22:18,656 ERROR [STDERR] at java.net.PlainSocketImpl.connect(PlainSocketI
mpl.java:182)
15:22:18,656 ERROR [STDERR] at java.net.SocksSocketImpl.connect(SocksSocketI
mpl.java:366)
15:22:18,781 ERROR [STDERR] at java.net.Socket.connect(Socket.java:520)
15:22:18,781 ERROR [STDERR] at java.net.Socket.connect(Socket.java:470)
15:22:18,781 ERROR [STDERR] at java.net.Socket.(Socket.java:367)
15:22:18,781 ERROR [STDERR] at java.net.Socket.(Socket.java:180)
15:22:18,781 ERROR [STDERR] at org.postgresql.core.PGStream.(PGStream.
java:62)
15:22:18,781 ERROR [STDERR] at org.postgresql.core.v3.ConnectionFactoryImpl.
openConnectionImpl(ConnectionFactoryImpl.java:77)
15:22:18,796 ERROR [STDERR] ... 27 more

But in normal servlet application running on Tomcat Apach server works fine and i can retrieve the data from the database without problem...

Now i want to retirve some data from the database on postgrsql..

CAn any one suggest me please....