0

I have been looking for the solution from 2 days and tried everything but still i am not able to resolve the issue i am facing. Issue : Invalid object name 'Info'

package test;
import java.sql.*;
public class DataConn {
public static void main(String arg[]){
    try{
        //Load JDBC driver
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

        //Establish connection
        String url = "jdbc:sqlserver://localhost\\SQL2014:1433;databaseName=Test;integratedSecurity=true";
        Connection con = DriverManager.getConnection(url);
        System.out.println("Connection success");

        //fetch data from Info
        Statement st = con.createStatement();
        String sql = "SELECT * FROM Info";
        ResultSet rs = st.executeQuery(sql);

        //extract
        while(rs.next()){
            String Name = rs.getString("Name");
            String Class = rs.getString("Class");
            int age = rs.getInt("Age");

            System.out.println("Name: "+Name +"\t"+"Class: "+Class+"\t"+"Age: "+age);
        }
        rs.close();
        con.close();
    }
    catch(Exception e){
        System.err.println("Got an Exception!");
        System.out.println(e.getMessage());
    }
}
}

Output:

Connection success
Invalid object name 'Info'.
Got an Exception!

I am using Eclipse and Sql server 2014, I tried most of the things like: 1. [databasename].[dbo].[Info] 2. Test.dbo.Info

But I end up getting the same error: Invalid Object Name

Here is the Screenshot of SqlServer 2014:

adrianbanks
  • 81,306
  • 22
  • 176
  • 206
topper1309
  • 151
  • 3
  • 16
  • From the error message it appears that "Info" is not the name of one of the tables in your database. Double check the case of the table name. – Bill W May 25 '16 at 20:10

2 Answers2

0

The Object Info here is the table you are trying to query. Make sure to check the below 1. make sure the table exists on the schema "TEST", and make sure the schema exists of course. It is possible that the table is on default schema. 2. make sure the user has permissions on that table 3. Make sure the result set columns match the table scheme

since the DB connection is successful, I only doubt the that the table doesn't exist on the schema. You can try default schema.

itsme_seenu
  • 340
  • 2
  • 8
  • I checked what i got to know is in the screenshot. Scheme is "dbo" Table name is "Info" and database name is "Test". – topper1309 May 25 '16 at 20:35
0

As the connection is successful it indicates that you do not have any schema named"Info". Check the sql database for the name of the table.

Murgin Boo
  • 67
  • 1
  • 10