• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 616
  • Last Modified:

Error: Invalid object name

Hi,
can somebody help with this exception that I'm recived after trying to execute the next query
sql = "select  * from tbl_user";
ResultSet rs = stmt.executeQuery(sql);
I have try adding the owner of the table and i still keep getting the same error. I can connect to the database. This is the output that I'm getting.



Successfully connected


Driver Information
Driver Name: SQLServer
Driver Version: 2.2.0022

Database Information
Database Name: Microsoft SQL Server
Database Version: Microsoft SQL Server  2000 - 8.00.760 (Intel X86)
        Dec 17 2002 14:22:05
        Copyright (c) 1988-2003 Microsoft Corporation
        Standard Edition on Windows NT 5.2 (Build 3790: )

java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Invalid object name 'tbl_user'.
        at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
        at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
        at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source)
        at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source)
        at com.microsoft.jdbc.sqlserver.tds.TDSExecuteRequest.processReplyToken(Unknown Source)
        at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source)
        at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.getNextResultType(Unknown Source)
        at com.microsoft.jdbc.base.BaseStatement.commonTransitionToState(Unknown Source)
        at com.microsoft.jdbc.base.BaseStatement.postImplExecute(Unknown Source)
        at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source)
        at com.microsoft.jdbc.base.BaseStatement.executeQueryInternal(Unknown Source)
        at com.microsoft.jdbc.base.BaseStatement.executeQuery(Unknown Source)
        at hn.claro.prepago.Test.<init>(Test.java:75)
        at hn.claro.prepago.Test.main(Test.java:124)

DriverManager.registerDriver(new com.microsoft.jdbc.sqlserver.SQLServerDriver());
        Connection connection = DriverManager.getConnection("jdbc:microsoft:sqlserver://host:1433", "sa", "");
        if (connection != null) {
            System.out.println();
            System.out.println("Successfully connected");
            System.out.println();
            // Meta data
            DatabaseMetaData meta = connection.getMetaData();
            System.out.println("\nDriver Information");
            System.out.println("Driver Name: " + meta.getDriverName());
            System.out.println("Driver Version: " + meta.getDriverVersion());
            System.out.println("\nDatabase Information ");
            System.out.println("Database Name: " + meta.getDatabaseProductName());
            System.out.println("Database Version: " + meta.getDatabaseProductVersion());

            Statement stmt = connection.createStatement();

try{
sql = "select  * from tbl_user";
ResultSet rs = stmt.executeQuery(sql);
} catch (Exception ex) {
                ex.printStackTrace();
            }

Open in new window

0
rzepeda57
Asked:
rzepeda57
1 Solution
 
objectsCommented:
>         Connection connection = DriverManager.getConnection("jdbc:microsoft:sqlserver://host:1433", "sa", "");


you haven't specified the database name


        Connection connection = DriverManager.getConnection("jdbc:microsoft:sqlserver://host:1433;DatabaseName=abc", "sa", "");
0
 
rzepeda57Author Commented:
Thanks for the help.
0
 
for_yanCommented:
Still it prints

Successfully connected

etc.

are you sure you have the table tbl_user ?

Did you run thsi query directly from SQL prompt?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now