File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Error in JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Error in JDBC" Watch "Error in JDBC" New topic

Error in JDBC

pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 323


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 :

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

Joined: Apr 26, 2010
Posts: 323

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

Joined: Dec 20, 2006
Posts: 2565

You need to put Oracle's JDBC driver in the classpath when you run your code.

OCUP UML fundamental and ITIL foundation
I agree. Here's the link:
subject: Error in JDBC
It's not a secret anymore!