public class ManageConnectionClass {
private String dbURL="jdbcracle: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...
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.
Retired horse trader.
Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
Dieter Quickfend
Ranch Hand
Joined: Aug 06, 2010
Posts: 280
posted
0
You probably need to put the right driver jar on your classpath.
Oracle Certified Professional Java Programmer
Kiran kk
Greenhorn
Joined: Jun 17, 2011
Posts: 9
posted
0
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....
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
Joined: Jun 17, 2011
Posts: 9
posted
0
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
Ranch Hand
Joined: Aug 06, 2010
Posts: 280
posted
0
Then you have a problem connecting. Check if all your data is correct... Username, password, driver string, hostname, and port.
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.
amit punekar
Ranch Hand
Joined: May 14, 2004
Posts: 488
posted
0
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
Joined: Jun 17, 2011
Posts: 9
posted
0
Dieter Quickfend wrote:Then you have a problem connecting. Check if all your data is correct... Username, password, driver string, hostname, and port.
the username and password are working as i checked that with my oracle sql puls..
Kiran kk
Greenhorn
Joined: Jun 17, 2011
Posts: 9
posted
0
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
Ranch Hand
Joined: Aug 06, 2010
Posts: 280
posted
0
try using your real IP address instead of localhost.
Kiran kk
Greenhorn
Joined: Jun 17, 2011
Posts: 9
posted
0
Dieter Quickfend wrote:try using your real IP address instead of localhost.
Thank you very much... It worked!!!The ping succeeded
Dieter Quickfend
Ranch Hand
Joined: Aug 06, 2010
Posts: 280
posted
0
You're welcome.
Kiran kk
Greenhorn
Joined: Jun 17, 2011
Posts: 9
posted
0
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 jdbcracle:thin:@192.168.1.10:1521:ORCL
11:10:11,024 INFO [STDOUT] Exceptionjava.lang.NullPointerException"