• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

ClassNotFoundException while trying to connect to Oracle

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi my program is unable to connect to the database it shows the ClassNotFound Exception
Below is the Program

package model;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ManageConnectionClass {
private String dbURL="jdbc:oracle:thin:@localhost:1521:ORCL";
private String dbUserName="system";
private String dbPassword="default";

public Connection getConnection(){
Connection conn=null;
try{
try {
Class.forName("oracle.jdbc.OracleDriver");
} catch (ClassNotFoundException e) {
System.out.println("Class not found");
System.out.println(e);
}
conn=DriverManager.getConnection(dbURL,dbUserName,dbPassword);
}
catch(SQLException e){
System.out.println("Could not connect to DB");
}
return conn;
}
public void putConnection(Connection conn){
if(conn!=null)
{
try {
conn.close();
}
catch (SQLException e)
{
System.out.println("Could not close the connection");

}
}
}


public static void main(String args[]){
try {
System.out.println(new ManageConnectionClass().getConnection());
} catch (Exception e) {
System.out.println("Exception"+e);
}

}
}
and i'm invoking this using the main method......... I wasted a whole day for this .... please help me out...
 
Ranch Hand
Posts: 479
1
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Which line throws ClassNotFoundException?
 
Kiran kk
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Raj Kamal wrote:
Which line throws ClassNotFoundException?



at this line

Class.forName("oracle.jdbc.OracleDriver");
 
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to add the Oracle JDBC driver jar to your class path. When you use this in your servlet the driver jar must be placed in the WEB-INF/lib directory of your war file.
 
Bartender
Posts: 543
4
Netbeans IDE Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You probably need to put the right driver jar on your classpath.
 
Kiran kk
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

James Sabre wrote:You need to add the Oracle JDBC driver jar to your class path. When you use this in your servlet the driver jar must be placed in the WEB-INF/lib directory of your war file.



I'm using eclipse galileo.... still do i need to add? I added the classes12.jar file in my database connections....even the pinging also failed....
 
James Sabre
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kiran kk wrote:

I'm using eclipse galileo.... still do i need to add? I added the classes12.jar file in my database connections...


I no longer use Eclipse so I don't know the proper approach to this.


.even the pinging also failed....



I don't understand. How were you 'pinging'?
 
Kiran kk
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i'm using eclipse galileo.. In that i created a new database connection selecting Oracle.... In the new Driver definition(oracle thin driver 10) i made modifications like removing the classes14 jar,adding the classes12 jar, setting the SID,username ,password... i made these modifications in the properties also... When i click the test connection button it says the ping failed
 
Dieter Quickfend
Bartender
Posts: 543
4
Netbeans IDE Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then you have a problem connecting. Check if all your data is correct... Username, password, driver string, hostname, and port.
 
James Sabre
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dieter Quickfend wrote:Then you have a problem connecting. Check if all your data is correct... Username, password, driver string, hostname, and port.



This may be true BUT the original ClassNotFound exception still points to a classpath problem and I suspect this should be addressed first.
 
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Two things to check
1) Do you see the Class for which ClassNotFound is thrown in the JAR that you added in Eclipse
2) Right click the java project and check the Java Build Path. It should have correct location of the JDBC driver's Jar file.

Regards,
Amit
 
Kiran kk
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dieter Quickfend wrote:Then you have a problem connecting. Check if all your data is correct... Username, password, driver string, hostname, and port.



Username:system
password:default
driver string:jdbc:oracle:thin:@localhost:1521:ORCL
hostname:ORCL

the username and password are working as i checked that with my oracle sql puls..
 
Kiran kk
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

amit punekar wrote:Hi,
Two things to check
1) Do you see the Class for which ClassNotFound is thrown in the JAR that you added in Eclipse
2) Right click the java project and check the Java Build Path. It should have correct location of the JDBC driver's Jar file.

Regards,
Amit



Thank you Amit For your Reply The ClassNotFound problem is resolved but still i got SQL exception saying that the network adapter could not establish the connection
 
Dieter Quickfend
Bartender
Posts: 543
4
Netbeans IDE Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try using your real IP address instead of localhost.
 
Kiran kk
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dieter Quickfend wrote:try using your real IP address instead of localhost.



Thank you very much... It worked!!!The ping succeeded
 
Dieter Quickfend
Bartender
Posts: 543
4
Netbeans IDE Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome.
 
Kiran kk
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dieter Quickfend wrote:You're welcome.



This is my Servlet class


This is the model class



This is the class for getting connection to the Database




This is the code to add a movie to the pyramid table.. When i executed it including main method the insertion is happened but when i removed the main method it's showing an error "Class not foundjava.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
11:10:11,022 INFO [STDOUT] java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
11:10:11,023 INFO [STDOUT] Could not connect to DBjava.sql.SQLException: No suitable driver found for jdbc:oracle:thin:@192.168.1.10:1521:ORCL
11:10:11,024 INFO [STDOUT] Exceptionjava.lang.NullPointerException"


How can i overcome this error? help me


 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to add the Oracle JDBC driver to your classpath. One way to do this in Eclipse is to add the JDBC JAR file to the project's build path.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic