Error: Invalid object name

Posted on 2011-04-27
Last Modified: 2012-05-11
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 Source)
        at Source)
        at Source)
        at Source)
        at Source)
        at Source)
        at Source)
        at Source)
        at Source)
        at Source)
        at Source)
        at Source)
        at hn.claro.prepago.Test.<init>(
        at hn.claro.prepago.Test.main(

        Connection connection = DriverManager.getConnection("jdbc:microsoft:sqlserver://host:1433", "sa", "");
        if (connection != null) {
            System.out.println("Successfully connected");
            // 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();

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

Open in new window

Question by:rzepeda57
    LVL 92

    Accepted Solution

    >         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", "");

    Author Closing Comment

    Thanks for the help.
    LVL 47

    Expert Comment

    Still it prints

    Successfully connected


    are you sure you have the table tbl_user ?

    Did you run thsi query directly from SQL prompt?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Suggested Solutions

    By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
    Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
    This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now