This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes Access database using JDBC error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Access database using JDBC error" Watch "Access database using JDBC error" New topic
Author

Access database using JDBC error

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi All
I'm trying to access databaseusing jdbc and i'm getting this error:
Exception java.lang.ClassNotFoundException must be caught, or it must be declared in the throws clause of this constructor.
Class.forName
sometime in this statment :
Class.forName( "microsoft.jdbc.odbc.JdbcOdbcDriver");
I put instead microsoft sun and i still getting the same error.
here the java file:

import java.sql.*;
import java.lang.*;

public class myJdbc
{
public myJdbc()
{
String url="jdbc dbc:sample";
String query= "SELECT * FROM PERSON ";
//boolean more;
Statement stmt ;

try
{
Class.forName( "microsoft.jdbc.odbc.JdbcOdbcDriver");
Connection con =DriverManager.getConnection(url,"matt","matt");
stmt= con.createStatement();
ResultSet rs = stmt.executeQuery(query);
//while(more = rs.next())
while( rs.next())
{
int number = rs.getInt("PERSON#");
String firstName = rs.getString("FIRST");
String lastName = rs.getString("LAST");
System.out.println(number + " " + firstName + " " + lastName);
}
rs.close();
stmt.close();
con.close();
}
catch(SQLException ex )
{
ex.printStackTrace();
}
}
public static void main(String args[])
{
myJdbc my = new myJdbc();
}
}
thanks for your time.
Srividya Shiv
Ranch Hand

Joined: Jul 20, 2000
Posts: 31
Originally posted by enirad:
[B]Hi
-----------------------------------------------------------------
I'm trying to access databaseusing jdbc and i'm getting this error:
Exception java.lang.ClassNotFoundException must be caught, or it must be declared in the throws clause of this constructor.
Class.forName
sometime in this statment :
Class.forName( "microsoft.jdbc.odbc.JdbcOdbcDriver");
I put instead microsoft sun and i still getting the same error.
here the java file:
-----------------------------------------------------------------There is a class in java called 'Class'. So must catch the exception that is thrown when 'Class' is not found.Otherwise instead of catching just SQLException, U can catch Exception' itself.
Hope this solves ur problem
---------------------------------------
Your String 'url' should read "jdbc dbc:sample"(maybe u missed the colon).

[This message has been edited by Srividya Shiv (edited August 01, 2000).]
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi!
The error means that the class "microsoft.jdbc.odbc.JdbcOdbcDriver" was not found in your class path.
Make sure of it's location, but I think it should be "sun" instead of "microsoft".

Originally posted by enirad:
[B]Hi All
I'm trying to access databaseusing jdbc and i'm getting this error:
Exception java.lang.ClassNotFoundException must be caught, or it must be declared in the throws clause of this constructor.
Class.forName
sometime in this statment :
Class.forName( "microsoft.jdbc.odbc.JdbcOdbcDriver");
I put instead microsoft sun and i still getting the same error.
here the java file:
angel aracena
Greenhorn

Joined: Aug 30, 2004
Posts: 3
I think you need to add the "}catch(ClassNotFoundException" to your program.
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

can you please use code-tags?

I don't respond to unreadable code anymore. I only get angry.


http://home.arcor.de/hirnstrom/bewerbung
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30130
    
150

Angel,
Note that the original post is 4 years old. I doubt the poster still needs an answer.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Access database using JDBC error
 
Similar Threads
Access database using JDBC error
Access database using JDBC error
connecting to ms access database
JdbcOdbc Connection
URL error (DSN not found)