java.lang.ClassNotFoundException: com.mysql.jdbc.Driver [duplicate] - java

This question already has answers here:
How to install JDBC driver in Eclipse web project without facing java.lang.ClassNotFoundexception
(13 answers)
Closed 7 years ago.
I am getting java.lang.ClassNotFoundException: com.mysql.jdbc.Driver in my dynamic web application even though I have set build path correctly in Eclipse for mysql connector. I am pretty sure that I have set built path correctly. I doubled checked that.
I ran through so many same kind of questions in stackoverflow. All of them suggest to set build path in Eclipse.
My question is, are there any other ways that can generate java.lang.ClassNotFoundException: com.mysql.jdbc.Driver error? If so , how to solve that?
Thank you!

Keep your mysql-connector-java.jar file inside Web-INF folder -> lib and add it in classpath and then export your WAR and deploy.
This Documentation - http://tomcat.apache.org/tomcat-7.0-doc/class-loader-howto.html
says
Therefore, from the perspective of a web application, class or resource loading looks in the following repositories, in this order:
Bootstrap classes of your JVM
/WEB-INF/classes of your web application
/WEB-INF/lib/*.jar of your web application <----------
System class loader classes (described above)
Common class loader classes (described above)

Related

No suitable driver found for jdbc:oracle:thin:#localhost:1522:xe [duplicate]

This question already has answers here:
The infamous java.sql.SQLException: No suitable driver found
(21 answers)
Closed 7 years ago.
I am trying to create a connection to my database(oracle), when I put test my code using the main method, it works seamlessly.
However, when trying to access it through Tomcat 8, it fails with error:
No suitable driver found for "jdbc:oracle:thin:#localhost:1522:xe"
I have added ojdbc6 jar file to lib and also configured the built path.
The url,use, password is correct still it give the above error.
when i paste the same code in main it runs but in tomcat it doesn't.
Put the ojdbc6.jar file in tomcat/lib folder or in your application lib <Aplication>/WEB-INF/lib to get it work.

JSP & mysql throws java.lang.classNotFoundException:com.mysql.jdbc.driver [duplicate]

This question already has answers here:
Connect Java to a MySQL database
(14 answers)
Closed 7 years ago.
I have the same problem that but it is Ubuntu 14.04. I tried to execute a web page with the help of JSP & mysql as a database. After execution in tomcat logs it gives the error of
"java.lang.classNotFoundException:com.mysql.jdbc.driver"
The hint that I got is that I have to keep my mysql-connector.jar file somewhere such that my tomcat will able to access it.
Your Driver class name need to be capitalized. Use like
com.mysql.jdbc.Driver
instead of
com.mysql.jdbc.driver
You can Use Driver instead of driver
or
If you get this error when you are running it, then probably its because you have not included mysql-connector JAR file to your webserver's lib folder. you can Easily Check on Class Path as well . may be jar File Broken . Right Click the project -- > build path -- > configure build path
Thanks

Why am I getting the wrong MANIFEST? [duplicate]

This question already has answers here:
Reading my own Jar's Manifest
(13 answers)
Closed 8 years ago.
I'm trying to access the MANIFEST.MF file in my java application.
I'm doing the following
//prints /usr/local/apache-tomcat-8.0.9/webapps/MyProject/WEB-INF/lib/activation-1.1.jar!/META-INF/MANIFEST.MF
System.out.println( "We are looking at "+this.getClass().getClassLoader()
.getResource("META-INF/MANIFEST.MF"));`
//Im looking to print /usr/local/apache-tomcat-8.0.9/webapps/MyProject/META-INF/MANIFEST.MF
//prints-/usr/local/apache-tomcat-8.0.9/lib/
System.out.println("The base path is"+this.getClass().getClassLoader()
.getResource("."));
Here's the directory structure
MyProject
-src/main/java/my/packages/MyClass.java
-target
-MyProject.war
Any thoughts on how I can correct my code would be great.
Directory structure of my war
Myproject
META-INF apidocs other folders
WEB-INF
You need to use the ServletContext.getResourceAsStream
I have found the classloader method not as reliable for MANIFEST files on web apps.
Also it's not going to reliably work well if your running your app from maven or eclipse wtp if your manifest is generated by your build process.
The real duplicate of the question: How do I read the manifest file for a webapp running in apache tomcat?

Need the JAR file for a javax.servlet.http.HttpServletRequest [duplicate]

This question already has answers here:
How do I import the javax.servlet / jakarta.servlet API in my Eclipse project?
(16 answers)
Closed 6 years ago.
I am modifying behavior of a web-app(server & client) running on web-sphere. I have de-compiled the code and just need to make minor changes and redeploy the code.
For this I made a simple Java Project with Eclipse EE and loaded all the de-compiled code. I only need the *.class files which I will convert to a JAR and place them at their proper place. The thing is there is a dependency which is not being resolved javax.servlet.http.HttpServletRequest so my project is not building
How to resolve this dependency?
If this dependency cannot be resolved than my guess is I could just get the JAR file for javax.servlet.http.HttpServletRequest and add to the Project's Build Path as an external JAR.
Where can I find the JAR for javax.servlet.http.HttpServletRequest
p.s. I am new to JAVA so I don't know much about HttpServletRequest also I am using Java 1.6 JRE.
A long time ago I used to manually add the servletapi.jar into my eclipse project, but that is a bad practice.
Now I just create a Dynamic Web Project, then add a server (usually Tomcat), then right click on the new project - select properties - select project facets and add the Tomcat Server as the runtime. It has the files you need. Once you hit the apply button and okay button it will resolve the missing import files.
Here is a step by step description from a similar question on SO: How do I import the javax.servlet API in my Eclipse project?
You'll want to add the Servlet API as a "provided" dependency. That is, you only use it to compile the code, but you don't need to package it with your web application since your web container will already contain a copy of it.
Just Download Servlet.jar file from below link.
http://www.java2s.com/Code/Jar/s/Downloadservletapi30jar.htm
add this jar file into your project using build path in eclipse.

java.lang.ClassNotFoundException in JDBC program [duplicate]

This question already has answers here:
java.lang.ClassNotFoundException: org.postgresql.Driver
(2 answers)
Closed 9 years ago.
I'm making a simple JDBC program in java SE 7 but after compiling program it's giving "java.lang.ClassNotFoundException: org.postgreasql.Driver" error i followed this link http://docs.oracle.com/javase/7/docs/technotes/guides/jdbc/ but not getting yet so please help.
possibly you may not be setting the path of jdbc driver
follow the steps
Right click on your project
click buildpath->configure Build Path
click libraries tab
Click add external jars and give the path of driver
This:
org.postgreasql.Driver
should likely be
org.postgresql.Driver
THe name of the driver is wrong also. Should be org.postgresql.Driver iso org.postgreasql.Driver. So maybe a typo in your java code where you do Class.forname()
You would have to add the JAR file to your classpath for org.postgresql.Driver, You can download it from HERE .
You have to add the jdbc jar file on your build path. Firstly you have to download the jar from the link you provided. Then add it to build path.
If you use eclipse: Right click on your project at the package explorer->Configure Build Path->Libraries->Add external jar->select your jar.
Please check your connection String url or connection driver and run code.

Categories

Resources