473,498 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

dmjpro
2,476 Top Contributor
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 7202
JosAH
11,448 Recognized Expert MVP
Is your postgreSQL jar in your classpath on your linux machine?

kind regards,

Jos
Jan 17 '09 #2
dmjpro
2,476 Top Contributor
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 Top Contributor
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 Top Contributor
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 Top Contributor
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 Recognized Expert MVP
@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 Top Contributor
What Environments u telling about ?
And i meant to say why it looks from different locations .. ?
Jan 19 '09 #8
JosAH
11,448 Recognized Expert MVP
@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 Top Contributor
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 MVP
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
10805
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
6783
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
4471
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
22090
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
9196
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
3947
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
2714
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
4713
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
7125
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
7002
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7165
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
7203
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...
1
6885
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
7379
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...
0
5462
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
290
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.