Click to See Complete Forum and Search --> : [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name


bkimelman
November 3rd, 2002, 09:49 AM
I have a MS Sqlserver 2000 database installed on my Windows NT4 PC.

I want ao access the database from a java program using JDBC - ODBC.

Note : a datasource name of "NORTHDS" was given during setup of sqlserver2000.

Here are the relevant lines from my java source code :
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
datasource = "NORTHDS";
url = "jdbc:odbc:" + datasource;
con = DriverManager.getConnection(url,username,password);
Statement stmt = con.createStatement();
query = "SELECT * from " + datasource + "." + username + "." + tablename;
ResultSet rs = stmt.executeQuery(query);

I am successfully able to create a connection and create a statement, but the
execution of the query fails with the error message :
java.sql.SQLException:
[Microsoft][ODBC SQL Server Driver][SQL Server]
Invalid object name 'NORTHDS.Admin.Customers'.

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

I have used the program "Microsoft Access" to verify that the database
table "Customers" (which is owned by "Admin") is intact and has records.

Any ideas/suggestions on how I can solve this problem ?

Goodz13
November 7th, 2002, 02:12 PM
Did you ever figure it out?

Your connection should already be connected to the right Database, and the User/Password should already be set, so try:

query = "SELECT * from " + tablename;
ResultSet rs = stmt.executeQuery(query);

bkimelman
November 7th, 2002, 02:30 PM
No, I never figured it out. I also looked into other forums and USENET news groups. A number of suggestions were made, but none helped.

Could you explain your reply to my post in greater detail?
What do you mean by "Your connection should ALREADY be connected to the right Database" ? How can I already be connected ?
Also, how can the User/Password already be set ?

Thanks for your continued help.

Goodz13
November 7th, 2002, 02:36 PM
This here:

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
datasource = "NORTHDS";
url = "jdbcdbc:" + datasource;
con = DriverManager.getConnection(url,username,password);
Sets the database, user and password, so your SQL statement shouldn't need the datasource and username.

I've never used access 2000 so I'm not totally sure but I'd think all you should need for your SQL statement would be:
"SELECT * from " + tablename;

bkimelman
November 7th, 2002, 02:41 PM
Thanks for the quick response. I tried your idea and I still get the same error condition.

Goodz13
November 7th, 2002, 03:02 PM
Where does it throw the exception?

Goodz13
November 7th, 2002, 03:08 PM
Earlier I should have said that I never used sqlserver2000.

I have Access 2000, and the sample DB that comes with that is called Northwind.mdb, are you sure the DB name isn't Northwind?

bkimelman
November 7th, 2002, 04:59 PM
The exception is thrown when my java code attempts to execute the statement

ResultSet rs = stmt.executeQuery(query);

Goodz13
November 8th, 2002, 10:00 AM
Are you using a third party driver or just the JDBC ODBC bridge?

bkimelman
November 8th, 2002, 10:27 AM
I downloaded the JDBC driver stuff Microsoft's website. The ODBC stuff was already part of my java environment.

Goodz13
November 11th, 2002, 12:06 PM
I just wanted to touch back with you. Have you figured it out yet?

I'm sorry I couldn't be of much help.

bkimelman
November 11th, 2002, 01:51 PM
No luck yet. I have found several more forums which I tend to explore.