Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2002
    Winnipeg, Manitoba, Canada

    Unanswered: [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name

    I have a ms sqlserver 2000 database installed on my Windows NT4 PC.

    I want to access this database from a java program using JDBC - ODBC

    Here are the relavent lines of code from my java source code file.

    Note : I am attempting to access the sample database "Northwind Traders" that came with the installation.

    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newI nstance();
    datasource = "NORTHDS";
    url = "jdbcdbc:" + datasource;
    con = DriverManager.getConnection(url,username,password) ;
    query = "SELECT * from " + datasource + "." + username + "." + tablename;
    ResultSet rs = stmt.executeQuery(query);

    The connection succeeds but the query fails with :
    java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL
    Server]Invalid object name 'NORTHDS.username.Customers'.

    Using the program "Microsoft Access" I was able to verify that the "Customers" table is intact.

    Any ideas ?

  2. #2
    Join Date
    Feb 2002
    Take a look at the following:

    In your select statement there are a couple of potential problems that you need to verify.

    select * from datasource.username.table ... which is returning 'NORTHDS.username.Customers'

    should be

    select * from Northwind.dbo.Customers ... (unless you renamed the database ...)

    In other words, check to make sure your are referencing the correct database/owner/table in your select statement. It appears that the variables you are using are incorrect. tablename appears to be ok, but the username variable is returning username. Also, the datasource variable may not be your database name.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts