Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Megan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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");
}

}
}
 
panchalee phookan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic