[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 567
  • Last Modified:

JDBC with Oracle:Driver Class?

I have been trying to establish a connection to Oracle database in my company and I can not even load the driver class.  Can someone help plz?

The host string ,port number, user name and passwords are all fine as I used them to log thru SQL Tools.
package package1;
 
import java.sql.*;
 
public class class1 {
 
	private void f()   {
                 try{
	//Class.forName("jdbc:oracle:thin");
	Class.forName("oracle.jdbc.driver.OracleDriver");
					
	}
	catch(ClassNotFoundException e){
	System.out.println("Driver not loaded");
	}
String url = "oracle.jdbc.driver.OracleDriver:@144.226.202.69:1521:CCRP";
try{
				
Connection con=DriverManager.getConnection(url, "COMM_USER","APP0NLY");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from stage2");
System.out.println(rs.getType());
	}
catch(SQLException e){
System.out.println("Connection could not be established");
				}
				
	}
	
 
	public static void main(String[]fdfd){
		
		new class1().f();
	}
	
				}

Open in new window

0
perfect_tranquility
Asked:
perfect_tranquility
  • 3
  • 3
  • 2
2 Solutions
 
VenabiliCommented:
>>I can not even load the driver class
ClassNotFoundException  exception? Then you just do not have it in your classpath

Oh - and the URL for oracle with the thin driver should start with:
jdbc:oracle:thin:
not the full Driver path. The full Driver path is needed only for loading the driver. I see that you tried to load the class with the connection string so you just have them in the wrong order.
See this for some more details on the connection string: http://www.orafaq.com/wiki/JDBC 
and see http://www.java-tips.org/other-api-tips/jdbc/how-to-connect-oracle-server-using-jdbc-4.html for example on how to connect. The Driver path is differetn but the rest remains the same

Let me know if I can find with anything else.
0
 
Ramakanta SahooCommented:
Try This It may Help You.It worked for me. :)
try {
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@dbhostname:portnumber:dbsid, dbusername, dbpassword);
-----
---
-----
} catch (SQLException e) {
            e.printStackTrace();
}

Open in new window

0
 
VenabiliCommented:
This won't even compile rks_86. :)
Not to mention that it does not add anything to what I posted days ago... So what was the point in posting it?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
perfect_tranquilityAuthor Commented:
no problem, plz give me a day or two. I will check both of them out and come back. I have always been just in giving points, not to worry friends.
0
 
Ramakanta SahooCommented:
Thank you Venabili:. I had not read your links before posting.:-) Sorry :-)
By the way I'm not a expert i just wanted to help him as i also faced exactly same :-)
perfect_tranquility, I DONT want any points  you can award Venabili full points. :-)
0
 
VenabiliCommented:
rks_86, it's not about the points :) The whole idea is to work as a team so... try to read what is already posted before jumping in a question (and this is in the rules by the way) :) PS: Did you see why your code does not compile? :)

perfect_tranquility, Sure. let me know if you need more assistance
0
 
Ramakanta SahooCommented:
Syntax error right
0
 
perfect_tranquilityAuthor Commented:
Please bear with me, I will be doing all this JDBC stuff on weekend, this way, I shall memorize it all for ever!

Thanks
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now