下面是错误代码。。
//----------------------------------
java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]连接占线导致另一个 hstmt
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLExecute(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.execute(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeUpdate(Unknown Source)
at com.dong.login.ServerThread.run(Server.java:60)
java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]连接占线导致另一个 hstmt
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLExecute(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.execute(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeUpdate(Unknown Source)
at com.dong.login.ServerThread.run(Server.java:60)
Close Socket...
end thread...
//----------------------------------
//下面是源程序代码
//=-------------------------------
package com.dong.login;import java.io.*;
import java.net.*;
import java.sql.*;
import java.util.Vector;
class ServerThread extends Thread{//继承线程
private Socket socket;//定义套接口
private BufferedReader in;//定义输入流
private PrintWriter out;//定义输出流
int no;//定义申请的jicq号码 public ServerThread(Socket s) throws IOException {//线程构造函数
socket=s;//取得传递参数
in=new BufferedReader(new InputStreamReader(socket.getInputStream()));//创建输入流
out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())),true);//创建输出流
start();//启动线程
} public void run(){//线程监听函数
try{
while(true){
String str=in.readLine();//取得输入字符串
if(str.equals("end")){System.out.println("receive 'end'");break;}//如果是结束就关闭连接
else if(str.equals("login")) {//如果是登录
try{
System.out.println("login");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//连接数据库
Connection c=DriverManager.getConnection("jdbc:odbc:jicq","sa","sa");
String sql="select nickname,password,ip,status,pic,email,info,place,sex from icq where icqno=?";
//准备从数据库选择呢称和密码
PreparedStatement prepare=c.prepareCall(sql);//设定数据库查寻条件
String icqno=in.readLine();
int g=Integer.parseInt(icqno);//取得输入的jicq号码
System.out.println("the icpno login:"+icqno);
String passwd=in.readLine().trim();//取得输入的密码
System.out.println("the password received:"+passwd);
prepare.clearParameters();
prepare.setInt(1,g);//设定参数
ResultSet r=prepare.executeQuery();//执行数据库查寻
if(r.next()){//以下比较输入的号码于密码是否相同
String pass = r.getString("password").trim();
System.out.println("the password from database:" + pass);
//如果相同就告诉客户ok
//并且更新数据库用户为在线
//以及注册用户的ip 地址
if(passwd.regionMatches(0,pass,0,pass.length()))
{
//if (passwd.equals(pass)) {
System.out.println("password matched successfully");
//out.println("ok");
// System.out.println("send 'OK' to client");
//*************register ipaddress
String setip = "update icq set ip=? where icqno=?";
PreparedStatement prest = c.prepareCall(setip);
prest.clearParameters();
prest.setString(1, socket.getInetAddress().getHostAddress());
prest.setInt(2, g); //g为取得输入的jicq号码
int set = prest.executeUpdate();//程序走到这个地方就已经出现了占线(hstmt)错误 System.out.println("update IP Status:"+set);
//*************ipaddress
//set status online
String status = "update icq set status=1 where icqno=?";
PreparedStatement prest2 = c.prepareCall(status);
prest2.clearParameters();
prest2.setInt(1, g); //g为取得输入的jicq号码
int set2 = prest2.executeUpdate();
System.out.println("set the icqno status online(1):"+set2);
//set online
out.println("ok");
System.out.println("send 'OK' to client,login finished");
//开始发送登录者的个人信息
out.println(r.getString("nickname"));
out.println(r.getString("ip"));
out.println(r.getString("status"));
out.println(r.getString("pic"));
out.println(r.getString("email"));
out.println(r.getString("info"));
out.println(r.getString("place"));
out.println(r.getString("sex"));
System.out.println("Send the loginer's info successfully");
}
//否者告诉客户失败
else {
System.out.println("password error!");
out.println("pwderror");///////////////////////////////////////////////////// send false
r.close();
c.close();
}
}
else{
System.out.println("the icqno is wrong,not in the db!");
out.println("usererror");/////////////////////////////////////////////////////// send false
System.out.println("send false");
r.close();
c.close();
}
}catch (Exception e){
out.println("false");
e.printStackTrace();}
socket.close();break;
}//end login
//登录结束
//处理上线结束
System.out.println("finished:"+str);
} //end while //处理str="end"
System.out.println("Close Socket...");
this.socket.close();//changed:add
System.out.println("end thread...");
this.yield();//changed:add
}
catch(IOException e){}//捕或异常
finally {try{socket.close();}
catch(IOException e){}
}//end try
}//end run
}//end class ServerThread
//主服务器类
public class Server{
public static void main(String args[])throws IOException{
ServerSocket s=new ServerSocket(10000);//在10000端口创建套接口
System.out.println("Server start.."+s);
try{
while(true){
Socket socket=s.accept();//无限监听客户的请求
System.out.println("Connection accept:"+socket+"(new Socket created)");
System.out.println("HOST:"+socket.getInetAddress().getHostAddress());
try{new ServerThread(socket);//创建新线程
}
catch(IOException e){
System.out.println(e.getMessage());
socket.close();}
}
}finally{s.close();}//捕或异常
}//end main
}//服务器程序结束
//--------------------------------
请高手指点以下
//----------------------------------
java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]连接占线导致另一个 hstmt
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLExecute(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.execute(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeUpdate(Unknown Source)
at com.dong.login.ServerThread.run(Server.java:60)
java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]连接占线导致另一个 hstmt
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLExecute(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.execute(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeUpdate(Unknown Source)
at com.dong.login.ServerThread.run(Server.java:60)
Close Socket...
end thread...
//----------------------------------
//下面是源程序代码
//=-------------------------------
package com.dong.login;import java.io.*;
import java.net.*;
import java.sql.*;
import java.util.Vector;
class ServerThread extends Thread{//继承线程
private Socket socket;//定义套接口
private BufferedReader in;//定义输入流
private PrintWriter out;//定义输出流
int no;//定义申请的jicq号码 public ServerThread(Socket s) throws IOException {//线程构造函数
socket=s;//取得传递参数
in=new BufferedReader(new InputStreamReader(socket.getInputStream()));//创建输入流
out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())),true);//创建输出流
start();//启动线程
} public void run(){//线程监听函数
try{
while(true){
String str=in.readLine();//取得输入字符串
if(str.equals("end")){System.out.println("receive 'end'");break;}//如果是结束就关闭连接
else if(str.equals("login")) {//如果是登录
try{
System.out.println("login");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//连接数据库
Connection c=DriverManager.getConnection("jdbc:odbc:jicq","sa","sa");
String sql="select nickname,password,ip,status,pic,email,info,place,sex from icq where icqno=?";
//准备从数据库选择呢称和密码
PreparedStatement prepare=c.prepareCall(sql);//设定数据库查寻条件
String icqno=in.readLine();
int g=Integer.parseInt(icqno);//取得输入的jicq号码
System.out.println("the icpno login:"+icqno);
String passwd=in.readLine().trim();//取得输入的密码
System.out.println("the password received:"+passwd);
prepare.clearParameters();
prepare.setInt(1,g);//设定参数
ResultSet r=prepare.executeQuery();//执行数据库查寻
if(r.next()){//以下比较输入的号码于密码是否相同
String pass = r.getString("password").trim();
System.out.println("the password from database:" + pass);
//如果相同就告诉客户ok
//并且更新数据库用户为在线
//以及注册用户的ip 地址
if(passwd.regionMatches(0,pass,0,pass.length()))
{
//if (passwd.equals(pass)) {
System.out.println("password matched successfully");
//out.println("ok");
// System.out.println("send 'OK' to client");
//*************register ipaddress
String setip = "update icq set ip=? where icqno=?";
PreparedStatement prest = c.prepareCall(setip);
prest.clearParameters();
prest.setString(1, socket.getInetAddress().getHostAddress());
prest.setInt(2, g); //g为取得输入的jicq号码
int set = prest.executeUpdate();//程序走到这个地方就已经出现了占线(hstmt)错误 System.out.println("update IP Status:"+set);
//*************ipaddress
//set status online
String status = "update icq set status=1 where icqno=?";
PreparedStatement prest2 = c.prepareCall(status);
prest2.clearParameters();
prest2.setInt(1, g); //g为取得输入的jicq号码
int set2 = prest2.executeUpdate();
System.out.println("set the icqno status online(1):"+set2);
//set online
out.println("ok");
System.out.println("send 'OK' to client,login finished");
//开始发送登录者的个人信息
out.println(r.getString("nickname"));
out.println(r.getString("ip"));
out.println(r.getString("status"));
out.println(r.getString("pic"));
out.println(r.getString("email"));
out.println(r.getString("info"));
out.println(r.getString("place"));
out.println(r.getString("sex"));
System.out.println("Send the loginer's info successfully");
}
//否者告诉客户失败
else {
System.out.println("password error!");
out.println("pwderror");///////////////////////////////////////////////////// send false
r.close();
c.close();
}
}
else{
System.out.println("the icqno is wrong,not in the db!");
out.println("usererror");/////////////////////////////////////////////////////// send false
System.out.println("send false");
r.close();
c.close();
}
}catch (Exception e){
out.println("false");
e.printStackTrace();}
socket.close();break;
}//end login
//登录结束
//处理上线结束
System.out.println("finished:"+str);
} //end while //处理str="end"
System.out.println("Close Socket...");
this.socket.close();//changed:add
System.out.println("end thread...");
this.yield();//changed:add
}
catch(IOException e){}//捕或异常
finally {try{socket.close();}
catch(IOException e){}
}//end try
}//end run
}//end class ServerThread
//主服务器类
public class Server{
public static void main(String args[])throws IOException{
ServerSocket s=new ServerSocket(10000);//在10000端口创建套接口
System.out.println("Server start.."+s);
try{
while(true){
Socket socket=s.accept();//无限监听客户的请求
System.out.println("Connection accept:"+socket+"(new Socket created)");
System.out.println("HOST:"+socket.getInetAddress().getHostAddress());
try{new ServerThread(socket);//创建新线程
}
catch(IOException e){
System.out.println(e.getMessage());
socket.close();}
}
}finally{s.close();}//捕或异常
}//end main
}//服务器程序结束
//--------------------------------
请高手指点以下
60行左右代码贴上来看看