aspose file tools*
The moose likes JDBC and the fly likes Beginner needs help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Beginner needs help" Watch "Beginner needs help" New topic
Author

Beginner needs help

John Huang
Greenhorn

Joined: Jan 21, 2001
Posts: 4
Hi,
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)
{
try
{ 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);

while(rset.next())
{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
regards
deeksha
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
Greenhorn

Joined: Jan 21, 2001
Posts: 4
Thanks, guys!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Beginner needs help