Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error in JDBC

 
pramod talekar
Ranch Hand
Posts: 328
Eclipse IDE Java Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Could you please advise me on the below issue :-

I'm trying to connect to the Oracle xe database on my machine.

This is in the code :

static String userid="hr" , password = "hr";
static String url = "jdbc:odbc:pramod";

--- - -- -- -- - -- --
The problem is with this part of the code :

try{
Connection con = DriverManager.getConnection(url,userid,password);

}catch(SQLException ex)
{
System.err.println("SQLException: " + ex.getMessage());
}


This is the output :
SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

The error is because of the url.
I checked the format of url on google. "jdbc:odbc:" is the correct format.
I wrote in the command prompt " CREATE DATABASE XYZ"
it gave the error as database already mounted.

So what should be the correct url
 
pramod talekar
Ranch Hand
Posts: 328
Eclipse IDE Java Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello again,

I made this change :
Connection con = DriverManager.getConnection("jdbc:oracle:thin:oracle_admin/oracle_admin@localhost:1521/XE");

but I'm still getting this error : No suitable driver found for jdbc:oracle:thin:oracle_admin/oracle_admin@localhost:1521/XE

I've installed Oracle XE.
Moreover, If I write Class.forName("oracle.jdbc.OracleDriver"); , it gives "Class not found exception". :confused:

Please advise.
 
Jan Cumps
Bartender
Posts: 2588
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to put Oracle's JDBC driver in the classpath when you run your code.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic