Rumah > pangkalan data > tutorial mysql > [SQLServer]对象名 'users' 无效。

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

WBOY
Lepaskan: 2016-06-07 15:12:49
asal
1277 orang telah melayarinya

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());
		}
	}
}
Salin selepas log masuk


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

 

 

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan