473,395 Members | 1,462 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

java.lang.ClassNotFoundException: (Driver Class) While Datasource got using JNDI

dmjpro
2,476 2GB
My context.xml...
Expand|Select|Wrap|Line Numbers
  1. <Context path="/JNDITest">
  2.     <Resource name="jdbc/dataSource" auth="Container"
  3.             type="javax.sql.DataSource"
  4.  
  5.             driverClassName="org.postgresql.Driver"
  6.             url="jdbc:postgresql://10.29.33.90:5432/Admin"
  7.             username="erp"
  8.             password="iiterp"
  9.  
  10.             maxIdle="50"
  11.             maxWait="60000"
  12.             maxActive="10"/>
  13. </Context>
  14.  
My Java Code ....
Expand|Select|Wrap|Line Numbers
  1. Context ctx = new InitialContext();
  2.             DataSource ds= (DataSource)ctx.lookup("java:/comp/env/jdbc/dataSource");
  3.             Connection l_con = ds.getConnection();
  4.  
It's working fine when I use Windows, but it's not working when I use Linux.
My Application server is Tomcat.
I mean to say why does it behave in different operating System .. Where I gone wrong ?
Jan 17 '09 #1
10 7198
JosAH
11,448 Expert 8TB
Is your postgreSQL jar in your classpath on your linux machine?

kind regards,

Jos
Jan 17 '09 #2
dmjpro
2,476 2GB
If the Jar is not in the classpath then why it runs properly in Windows ?

The jars are kept into the the folder WEB-INF/lib and i am making the war file and deploy it into the server...In Windows the war file is running OK ..but why not in Linux?
Jan 19 '09 #3
dmjpro
2,476 2GB
This is my another test ............... in Linux Tomcat Server.
My context.xml is ...
Expand|Select|Wrap|Line Numbers
  1. <Resource name="jdbc/EmployeeDB" auth="Container"
  2.             type="javax.sql.DataSource"
  3.      description="Employees Database for HR Applications"
  4. driverClassName="org.postgresql.Driver"
  5. url="jdbc:postgresql://10.29.32.68:5432/Admin"
  6. username="erp"
  7. password="iiterp"/>
  8.  
In my home.jsp the code snippet is ....
Expand|Select|Wrap|Line Numbers
  1. DriverManager.registerDriver(new org.postgresql.Driver());
  2.             Connection l_con = DriverManager.getConnection("jdbc:postgresql://10.29.32.68:5432/Admin","erp","iiterp");
  3.  
  4.             Context ctx = new InitialContext();
  5.             DataSource ds= (DataSource)ctx.lookup("java:/comp/env/jdbc/EmployeeDB");
  6.             Connection l_con1 = ds.getConnection();
  7.  

When it runs on Linux Tomcat server it shows an error in line ...
Expand|Select|Wrap|Line Numbers
  1. Connection l_con1 = ds.getConnection();
If the jar is not in class path then why it could execute successfully the line ...
Expand|Select|Wrap|Line Numbers
  1. DriverManager.registerDriver(new org.postgresql.Driver());
  2.             Connection l_con = DriverManager.getConnection("jdbc:postgresql://10.29.32.68:5432/Admin","erp","iiterp");
  3.  
  4.  
Please Help!
Jan 19 '09 #4
dmjpro
2,476 2GB
Now I could figure out the problem ...
Actually i didn't deploy into the Tomcat server running under Windows. ;)
Actually what happened, i was using Netbeans simply ran the Application and it got into work .. I don't understand how it did run.
But when i deployed the war file into the Window Tomcat Server then the same problem i was having.
Why does it happen .. when i load the Driver class using DriverManager then it looks from the WEB-INF/ib but when i try to get connection using JNDI look then it looks for another directory?
Jan 19 '09 #5
dmjpro
2,476 2GB
Yeah now it's working i put the driver class into the ext directory.
But still i am waiting for the answer ... why does it behave like differently in two cases ?
Jan 19 '09 #6
JosAH
11,448 Expert 8TB
@dmjpro
You gave the answer yourself: you didn't deploy on your Windows machine but made NetBeans do all the work for you. Make sure the 'environments' are identical on both computers. btw, don't just put your jars in the /ext directory to make things 'work'; most likely those jars don't belong there. Read this.

kind regards,

Jos
Jan 19 '09 #7
dmjpro
2,476 2GB
What Environments u telling about ?
And i meant to say why it looks from different locations .. ?
Jan 19 '09 #8
JosAH
11,448 Expert 8TB
@dmjpro
By equal 'environments' (mind the quotes) I meant: equal Java JRE versions, equal classpaths, equal available jars etc. I don't know what you mean by 'why it looks from different locations"; please elaborate.

kind regards,

Jos
Jan 19 '09 #9
dmjpro
2,476 2GB
When i try to connect using ...
Expand|Select|Wrap|Line Numbers
  1. DriverManager.registerDriver(new DriverClass());
  2. Connection l_con = DriverManager.getConnection(......);
  3.  
Then it looks from WEB-INF/lib but i use JNDI look up then it looks from class path .. I did mean that ... ;)
Jan 20 '09 #10
r035198x
13,262 8TB
On tomcat the WEB-INF/lib folder is on the path by default.
Jan 20 '09 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Fu Bo Xia | last post by:
the java.lang.Object.forName method takes a java class name and returns a Class object associated with that class. eg. Class myClass = Object.forName("java.lang.String"); by if i only know the...
0
by: Ravi Tallury | last post by:
Hi We are having issues with our application, certain portions of it stop responding while the rest of the application is fine. I am attaching the Java Core dump. If someone can let me know what...
0
by: JShurmatz | last post by:
If anyone can shed some light on this problem I would greatly appreciate it. I am unsuccessfully trying to use a database connnection retrieved from a pool configured using Java System Web...
3
by: dinesh prasad | last post by:
I'm trying to use a servlet to process a form, then send that data to an SQL server stored procedure. I'm using the WebLogic 8 App. server. I am able to retrieve database information, so I know my...
2
by: Kent Lewandowski | last post by:
hi all, Recently I wrote some stored procedures using java jdbc code (admittedly my first stab) and then tried to implement the same within java packages (for code reuse). I encountered...
2
by: astolpho | last post by:
I am using a slightly outdated reference book on J2EE programming. It gives 2 methods of creating a database used in its casestudies. The first is an ANT script that gives the following output: ...
5
by: Ananthu | last post by:
Hi I have done all the codings part for connecting mysql server with java application but when i try to compile,the compilation is successful and during execution i get the following message, ...
8
by: Ananthu | last post by:
Hi I have done all the codings part for connecting mysql with java in eclipse environment. Coding Part: import java.sql.Connection; import java.sql.DriverManager; public class...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.