Gui Guan’s BLOG

There’s more than one way to do it

Archive for the ‘Problem Solving’ Category

A small but very hard to find bug

Bug is a very disgusting thing in Computer Science. In one of my subjects project, I was required to write a Hearts card game robot player. I spent several hours finished the code, but it took me 2 days to debug it. :-(. A tiny bug found in the debugging process took me a whole night, which resulted to be mistyping variable Card as C, very embarrassed!

The funniest thing was that in order to find that tiny bug, I used a screen recording software recorded the whole playing process, then simulated the whole process by re-watching the recorded video again and again, but finally came to the conclusion that there was no bug in my program! I was nearly desperate, fortunately, an accidental warning msg “singleton variable” saved my life. 

Here is the video I recorded:

after playing for awhile, my robot(bottom one) stopped play.

Last week, during the prac 2 of CS IB, we were asked to program in Java to build a simple client/server system in which the server takes “commands” from the client and executes them. Due to the time restriction, we were only asked to implement the server, and use telnet to act as client to transact with server. You can have a look here for details.

1
2
3
4
5
ServerSocket server = new ServerSocket(6666);
Socket s= server.accept();
// We now have a client on the end of the socket s
BufferedReader in = new BufferedReader( new InputStreamReader( s.getInputStream()));
PrintWriter out = new PrintWriter(s.getOutputStream());

It’s no more than the knowledge above. Maybe the simplest nextwork program in Java world.

The telnet on lab’s Mac just work well, but after I brought my program to home and run on my own computer, I met a really troublesome problem with the Microsoft’s telnet in Windows XP.

1. First, I started my server.

telnet_1.png (more…)

根本原因:

访问数据库的用户有登录权限,但无操作表的权限

解决办法:

1. 在[企业控制台]窗口–[树]子窗口–[安全性]子树–[登录]项里将你使用的登陆用户的默认数据库设为你所使用的数据库。
2. 在[企业控制台]窗口–[树]子窗口–[安全性]子树–[登录]项里新增一个登录用户(在其中选择SQL Server 身份验证、服务器角色和要访问的数据库),以后便可用些新增用户访问你勾选的数据库了。

大家在用java连接ms sql时可能会这样的问题
原因是sa用户为系统用户,它虽然能够登陆数据库,但是数据库里边的权限都是dbo的,所以,我们现在为这个数据库重新建立一个用户.
当然,这个情况只发生在java里边. .net是不会这样的.
只要新建立一个用户,再在权限那分配权限做好就行了.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
public Connection getConnectionDB()
{
	String driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
	String ConnectionString = "jdbc:microsoft:sqlserver://localhost:1433; DatabaseName=test;";
	String userName = "username";
	String userPwd = "password";
 
	try {
		Class.forName(driverName);
		con = DriverManager.getConnection(ConnectionString, userName, userPwd);
		//System.out.println("Connection Successful!");
	} catch (Exception e) {
		e.printStackTrace();
	}
 
	return con;
}
 
	ConnectionDB prod=new ConnectionDB();
	Connection con=prod.getConnectionDB();
	CallableStatement callStmt =null;
	java.sql.Statement  stat  =  null;
	java.sql.ResultSet  rs  =  null;
 
	stat  =  con.createStatement();
	String  sql="select * from table";
	rs=stat.executeQuery(sql);

这几天为了安这个Microsoft SQL Server 2000搞得我焦头烂额。在安装的最后阶段(注册ActiveX控件的时候)总是出来个”Microsoft Visual C++ Runtime Library Runtime Error… abnormal program termination”

Microsoft Visual C++ Runtime Library Runtime Error!

我的安装环境为:Windows 2000 Advanced Server SP4, Windows XP Professional SP2

不知哪位朋友遇到跟我一样的错误,请在评论里写写。

以下为此问题的解决方案: (more…)