aspose file tools*
The moose likes JDBC 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
Bookmark "Error in JDBC" Watch "Error in JDBC" New topic
Author

Error in JDBC

pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 323

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


Thanks,
Pramod
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
Bartender

Joined: Dec 20, 2006
Posts: 2510
    
  10

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

OCUP UML fundamental and ITIL foundation
youtube channel
 
Don't get me started about those stupid light bulbs.
 
subject: Error in JDBC