I’m using the following Open Source softwares to build a J2EE Web Application:
Linux-- OS (Mandrake Linux 9.1) Apache-- Web Server (Tomcat 5) Tomcat-- Servlet Container MySQL-- Database
I have the following environment variables correctly in the /etc/profile file:
PATH� points to my J2SDK installation CLASSPATH � set to compile servlets and path to MYSQL CATALINA_HOME � points to Tomcat installation JAVA_HOME� points to JDK installation
try { Class.forName("com.mysql.jdbc.Driver").newInstance(); pw.println("the driver class is loaded");
con = DriverManager.getConnection("jdbc:mysql:///sun","root",""); pw.println("connection is established");
if(con!=null) System.out.println("Successfully connected to MySQL server using TCP/IP..."); stmt=con.createStatement(); rs=stmt.executeQuery("Select * from employee");
Inside Test Servlet.. The date is Fri Nov 05 00:58:46 EST 2004 Error Message -->com.mysql.jdbc.Driver Error -->java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
I’m using mysql-connector-java-3.0.15-ga. But, ironically I can query the database from a standalone Java Application.
Put the mysql jar in the <context>/WEB-INF/lib directory in Tomcat. Application servers typically ignore the classpath since this allows them to create separate running environments for each of the applications thay are running. Any jars placed in the WEB-INF/lib directory automatically get loaded and made available to your application context.
Jeroen Wenting
Ranch Hand
Joined: Oct 12, 2000
Posts: 5093
posted
0
the answer is contained in your question. You need to add the JDBC driver to the lib directory of your web application (I guess it's a jar file?).
Web applications have access ONLY to what's in their own library (WEB-INF/classes and WEB-INF/lib) and to default servlet functionality (servlet.jar or j2ee.jar) and nothing else. They're fully self-contained.
42
danny liu
Ranch Hand
Joined: Jan 22, 2004
Posts: 185
posted
0
If you want that mysql driver accessed by all applications, You may copy it to [tomcathome]/common/lib.
Hope it helps.
Dan
kunal Jaggi
Greenhorn
Joined: Sep 16, 2003
Posts: 17
posted
0
Hi!! It's working fine now...thanks.....
I want to change my public display name, how do I go about doing that??
Regards, Kunal Jaggi
Jeroen Wenting
Ranch Hand
Joined: Oct 12, 2000
Posts: 5093
posted
0
Change the "path" property to change the path via which your webapp can be approached.
To change the name displayed in the web application management application, change the web.xml for the webapp:
[ November 08, 2004: Message edited by: Jeroen Wenting ]
Unless you menat your JavaRanch display name, which can be changed here. To get there in future, to the right of the Moose Head is a 'My Profile' link, and you 'View/Edit Profile' there.