Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

package sun.jdbc does not exist

 
javed iqbal
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried to set the connection with my database (oracle) but every time I run the code I get the following error.

Error: package sun.jdbc does not exist

even though I have set the environment variables

the code is :



Class.forName(sun.jdbc.odbc.JdbcOdbcDriver);
conn=DriverManager.getConnection("jdbc dbc:newdsn","scott","tiger");

stmt=conn.createStatement();
rs=stmt.executeQuery("select * from emp");




newdsn is my dsn name

please help
 
Campbell Ritchie
Sheriff
Posts: 48396
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

You are not trying to get a class from sun.jdbc. You are trying to get a class from sun.jdbc.odbc.
Suggest you edit your post and click on "disable smilies in this post" at the bottom left. That will get rid of the !
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Class.forName requires a String, not a class name itself.

So change into and all should be fine.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...Unless you're not using a Sun JRE (eg IBM, HP etc) in which case the sun packages do not exist.

The extended lesson here is that the JdbcOdbc bridge is a dog and you're better connecting with a Type-4 (native Java) driver than relying on the bridge which isn't really supported and definitely not meant for production.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic