Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2005

Tip: Looking for answers? Try searching our database.

Using JNDI for remote Database

Thread view: 
Rahul - 24 Oct 2005 16:21 GMT
Hi all,

I am using tomcat JNDI for getting databse connection in my application

For this I have created a context.xml file in myAPP/META-INF
which looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/myAPP" docBase="myAPP" debug="5" reloadable="true"
privileged="true" crossContext="true">
<Resource name="jdbc/myAPP" auth="Container"
 type="javax.sql.DataSource" maxActive="30" maxIdle="10"
maxWait="6000"
 username="user" password="password"
 driverClassName="com.mysql.jdbc.Driver"
 url="jdbc:mysql://localhost:3306/myDB" removeAbandoned="true"
 autoReconnect="true"
 validationQuery="select now()"
 factory="org.apache.commons.dbcp.BasicDataSourceFactory"/>
</Context>

This works absolutely fine. But when I try to connect to a remote
database by changing url in above
file to "jdbc:mysql://192.168.5.65:3306/myDB" my application fails
It creates following exception while retrieving a connection:
org.apache.tomcat.dbcp.dbcp.SQLNestedException:
Cannot create PoolableConnectionFactory (Unknown database 'myDB')

code I have written for fetching connection is:

  Context ctx = (Context) new InitialContext()
    .lookup("java:comp/env");
  if (ctx == null)
  {
   throw new Exception("No context available");
  } else
  {
   dataSource = (DataSource) ctx.lookup("jdbc/icontact");
   Connection connection = dataSource.getConnection();
  }

can anybody what else I need to configure for getting databse
connections from remote machine.

thanks in advance
Andreas Thiele - 25 Oct 2005 00:02 GMT
> ...
> I am using tomcat JNDI for getting databse connection in my application
[quoted text clipped - 6 lines]
> Cannot create PoolableConnectionFactory (Unknown database 'myDB')
> ...

To me this seems to be a misconfiguration of the remote database. Are you
sure you have 'myDB' on the remote machine?

Changing the IP address as in your example should work, normally.

Andreas
Roedy Green - 25 Oct 2005 02:12 GMT
On Tue, 25 Oct 2005 01:02:05 +0200, "Andreas Thiele"
<nospam@nospam.com> wrote, quoted or indirectly quoted someone who
said :

>To me this seems to be a misconfiguration of the remote database. Are you
>sure you have 'myDB' on the remote machine?

Often "can't find" problems are actually spelling errors.  In Java,
presume everything is case sensitive and you won't get in trouble.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Rahul - 25 Oct 2005 06:07 GMT
I am absolutely sure about that. since I am using same script for
creating database on local machine as well as on remote machine
Rahul - 27 Oct 2005 06:53 GMT
Finally I figured out the problem

Actually the context file which tomcat creates for every application
in conf/<engine>/<application> folder was not getting updated.
It was having the localhost settings instead of remote server.

After correcting this file my application is working perfectly.

Thanks for the help


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.