package ssd;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.Statement;public class sdd { public static voID main(String[] srg) { String drivername = "com.microsoft.sqlserver.jdbc.sqlServerDriver"; // 加载JDBC驱动 String dbURL = "jdbc:microsoft:sqlserver://127.0.0.1:1433; Databasename=lianxi"; // 连接服务器和数据库 String username = "sa"; // 密码 String password = "sa"; Connection dbConn = null; Statement sta = null; ResultSet rs = null; try { Class.forname(drivername); dbConn = DriverManager.getConnection(dbURL,username,password); System.out.println("数据库连接成功!"); sta = dbConn.createStatement(); rs = sta.executequery("select * from users"); while(rs.next()){ System.out.println(rs.getString(1)); System.out.println(rs.getString(2)); } } catch (Exception e) { System.err.println("exception:" + e.getMessage()); } }}
出现 java.sql.sqlException: [Microsoft][sqlServer 2000 Driver for JDBC][sqlServer]对象名 'users' 无效。 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) ...... 代码中: String dbURL = "jdbc:microsoft:sqlserver://localhost:1433; Databasename=XXX 注意到了localhost:1433;后面有一空格,这样就找不到Database了,肯定也就找不到其中的数据表了。
总结以上是内存溢出为你收集整理的[SQLServer]对象名 'users' 无效。全部内容,希望文章能够帮你解决[SQLServer]对象名 'users' 无效。所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)