• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Beginner needs help

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 . . .

 
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
DSN is just a name given for your path to your .mdb file. DSN and table names within the .mdb file are not related.
 
John Huang
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, guys!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic