我从 2 天开始一直在寻找解决方案并尝试了所有方法,但我仍然无法解决我面临的问题。问题:无效的对象名称“信息”
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());
}
}
}
输出:
Connection success
Invalid object name 'Info'.
Got an Exception!
我正在使用 Eclipse 和 Sql server 2014,我尝试了大多数类似的东西:1. [databasename].[dbo].[Info] 2. Test.dbo.Info
但我最终得到了同样的错误:无效的对象名称
这是 SqlServer 2014 的屏幕截图: