Home > Database > Mysql Tutorial > [SQLServer]对象名 'users' 无效。

[SQLServer]对象名 'users' 无效。

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 15:12:49
Original
1310 people have browsed it

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.SQLServerDri

 

 

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());
		}
	}
}
Copy after login


出现
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了,肯定也就找不到其中的数据表了。

 

 

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Problem with tp6 connecting to sqlserver database
From 1970-01-01 08:00:00
0
0
0
Unable to connect to SQL Server in Laravel
From 1970-01-01 08:00:00
0
0
0
Methods of parsing MYD, MYI, and FRM files
From 1970-01-01 08:00:00
0
0
0
SQLSTATE: User login failed
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template