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:

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.