Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Class.forName(....) is not working

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, all,
I am trying to connect JDBC to MS access. To register the driver in the ODBC data souce administrator from the control panel, I selected MS access data base, then clicked Add, then selected Driver do MS access, click Finish and followed the instruction. However, I keep getting the "Exit from Class not found exception" (see the code below). I also tried the JDBCTest from Sun, but I got the "Failed to load JDBC/ODBC driver" exception. Please help. I thank you in advance.
class ConnectDb
{
public static void main(String[] args)
{
try
{
Class.forName("jdbc.odbc.JdbcOdbcDriver");
System.out.println("load class succeed!");
Connection myCon=DriverManager.getConnection("jdbc dbc:db1.mdb", "", "");
System.out.println(myCon);
Statement myStmt= myCon.createStatement();
System.out.println(myStmt);
}
catch (SQLException e)
{System.out.println("Exit from SQL Exception");
}
catch (ClassNotFoundException e)
{System.out.println("Exit from Class not found");
}

}
}
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Megan:
Hi, all,
I am trying to connect JDBC to MS access. To register the driver in the ODBC data souce administrator from the control panel, I selected MS access data base, then clicked Add, then selected Driver do MS access, click Finish and followed the instruction. However, I keep getting the "Exit from Class not found exception" (see the code below). I also tried the JDBCTest from Sun, but I got the "Failed to load JDBC/ODBC driver" exception. Please help. I thank you in advance.
class ConnectDb
{
public static void main(String[] args)
{
try
{
Class.forName("jdbc.odbc.JdbcOdbcDriver");
System.out.println("load class succeed!");
Connection myCon=DriverManager.getConnection("jdbc dbc:db1.mdb", "", "");
System.out.println(myCon);
Statement myStmt= myCon.createStatement();
System.out.println(myStmt);
}
catch (SQLException e)
{System.out.println("Exit from SQL Exception");
}
catch (ClassNotFoundException e)
{System.out.println("Exit from Class not found");
}

}
}


Hi Megan,
Replace
Class.forName("jdbc.odbc.JdbcOdbcDriver");
with
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
and
Connection myCon=DriverManager.getConnection("jdbc dbc:db1.mdb", "", "");
with
Connection myCon=DriverManager.getConnection("jdbc dbc:db1", "", "");
- you will be able to run your code successfully
:-)
Cheer up!!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic