File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Beginner needs help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Beginner needs help" Watch "Beginner needs help" New topic

Beginner needs help

John Huang

Joined: Jan 21, 2001
Posts: 4
I'm trying to retrieve something from MS Access database but having trouble. DSN name is MyAddress. It appears that the driver has been loaded but the table can not be found, shouldn't tableName be the same the the DSN name? Please help!! Thanks!
My code:

import java.sql.*;
public class AnsiLevelAccess
{ public static void main(String[]args)
{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c = DriverManager.getConnection("jdbc dbc:MyAddress");
DatabaseMetaData dbMetaData = c.getMetaData();
System.out.println(dbMetaData.getDatabaseProductName() +" "+dbMetaData.getDatabaseProductVersion());
System.out.println("Entry Level " +dbMetaData.supportsANSI92EntryLevelSQL());
System.out.println("Intermediate " +dbMetaData.supportsANSI92IntermediateSQL());
System.out.println("Full Level " +dbMetaData.supportsANSI92FullSQL());

Statement stm = c.createStatement();
String query = "SELECT * FROM MyAddress";

ResultSet rset = stm.executeQuery(query);

{System.out.println (" " + rset.getString(1));}

}catch(ClassNotFoundException cnfe)
{System.err.println("error loading driver:"+ cnfe);}

catch(SQLException sqle)
{System.err.println("Error connecting:"+sqle);}


Error message when execute:
ACCESS 04.00.0000
Entry Level true
Intermediate false
Full Level false
Error connecting:java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] The Microsoft Jet database engine cannot find the input table or query 'MyAddress'. Make sure it exists and that its name is spelled correctly.
Press any key to continue . . .

deekasha gunwant
Ranch Hand

Joined: May 06, 2000
Posts: 396
Hi John,
dsn name and table name are two diffrent things. dsn represents your whole database to which u'll be connecting. this database may consist of a number of tables.
we connect to a specific database using a dsn name.once the connection is established we can write and execute different queries involving any of the tables present in the database and in our query we need to specify the name of the specific table (and not the dsn ) from which we need to retrieve data.
hope this helps
Geoff Tate
Ranch Hand

Joined: Feb 06, 2001
Posts: 55
DSN is just a name given for your path to your .mdb file. DSN and table names within the .mdb file are not related.

<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR> fantastic, a towel? <HR></BLOCKQUOTE>
John Huang

Joined: Jan 21, 2001
Posts: 4
Thanks, guys!
I agree. Here's the link:
subject: Beginner needs help
It's not a secret anymore!