高分求助!关于数据库连接问题

jason_gy 2003-11-04 09:20:31
我用的是连接池,老是出现“连接占线导致另一个 hstmt ”,这是什么问题?
怎么解决?
...全文
107 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
lovelanzhi716 2003-11-17
  • 打赏
  • 举报
回复
是你的驱动程序不行,你是用的jdbc-odbc吧
它好像不行,你下载一个sql2000 for jdbc就可以了
xqg1130 2003-11-17
  • 打赏
  • 举报
回复
关注
jason_gy 2003-11-17
  • 打赏
  • 举报
回复
我是这样用的请各位看看有什么问题???

/*******************
该程序实现“系统登陆的默认页面‘中的存储过程,待办事务、个人消息、公告栏
*******************/
package oadb;
import java.sql.*;
import java.io.*;
import java.util.Date;
import java.text.SimpleDateFormat;

public class Main{
private CallableStatement stmtProc=null;//定义存储过程的语句对象
private CallableStatement stmtPub=null;//定义存储过程的语句对象
Statement stmt = null;
private Connection Con = null;
private ConnManager Cmgr;

public Main(){
try{
Cmgr=ConnManager.getInstance();
if(Cmgr == null){
return;
}
Con = Cmgr.getConnection();///申请连接

Cmgr.freeConnection(Con);//释放连接
}catch(Exception e){
System.err.println("系统登陆的默认页面取得连接错误:" + e.getMessage());
}
}
//-----------------------------显示待办事务列表---------------------------------------------------
public ResultSet UndoAffair(String S_CurUserID){
ResultSet R_UA = null ; //记录集
String Sql = "SELECT Rtrim(AffairType) AS AffairType, AffairFileID, AffairTitle, UrgentLevel, CurNodeName, SendUserName, FileState, CONVERT(varchar(16), ArriveTime, 20) AS ArriveTime FROM UndoAffair where UserID='"+S_CurUserID+"'";
try{
stmt = Con.createStatement();
R_UA = stmt.executeQuery(Sql);
}
catch(Exception sqld){
System.err.println("显示待办事务列表储过程错误:"+sqld.getMessage());
}
stmt=null;
return R_UA;
}
//-----------------------------------------显示个人消息列表---------------------------------------
public ResultSet MsgPerson(String S_CurUserID){
ResultSet R_MPer = null;
String Sql ="select MessageID,Title,UserName,DeptName,CONVERT(varchar(16), SendDate, 20) AS SendDate from V_MsgPerson where (getdate()<AvailedTime)and (BorwserID='"+S_CurUserID+"')";
try{
stmt = Con.createStatement();
R_MPer = stmt.executeQuery(Sql);
}
catch(Exception sqld){
System.err.println("显示个人消息列表,储过程错误"+sqld.getMessage());
}
stmt=null;
return R_MPer;
}
//-------------------------------------------显示公告栏列表----------------------------------------
public ResultSet MsgPub(){
String Sql = null;
ResultSet R_MPub = null;
try {
Sql="{CALL Pr_MsgPub}";
stmtPub=Con.prepareCall(Sql);
R_MPub = stmtPub.executeQuery();
stmtPub=null;
}catch(SQLException ex){
System.err.println("显示公告栏列表,储过程错误:" + ex.getMessage());
}
return R_MPub;
}
//------------------------------计算两个日期的间隔天数----------------------------------------------
public long Date_Compare(String S_DateStart,String S_DateEnd){
SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");
long day=0;
try{
java.util.Date date= myFormatter.parse(S_DateStart);
java.util.Date mydate= myFormatter.parse(S_DateEnd);
day=(date.getTime()-mydate.getTime())/(24*60*60*1000);
//System.out.println(day);
}catch(Exception e){System.err.println("计算两个日期的间隔天数错误:" + e.getMessage());}
return day;
}
//---------------------------------------取得服务器时间--------------------------------------------
public String Sys_Date(){
String strSql = null;
String str_date = "";
String D_SysDate = "";
try {
strSql="{call Pr_CurSysDateTime(?)}";
stmtProc=Con.prepareCall(strSql);
stmtProc.setString(1,str_date);
stmtProc.registerOutParameter(1,java.sql.Types.VARCHAR);
stmtProc.execute();
D_SysDate = stmtProc.getString(1);
stmtProc.close();
stmtProc=null;
}catch(SQLException ex){
System.err.println("取得服务器时间,储过程错误:" + ex.getMessage());
}
return D_SysDate;
}
//------------------------------------从消息提示表中查询当前人的数据-----------------------------------.
public String MsgReSet(String S_CurUserID){
String Sql = "Select Rtrim(MsgMatter) as MsgMatter,Rtrim(UserName) as UserName,CONVERT(varchar(16), ArriveTime, 20) AS ArriveTime From V_MsgHint where UserID='"+S_CurUserID+"'";
ResultSet Rs = null;
String S_MsgTable="<table border='1' width='100%' cellspacing='1'>";
String S_MsgMatter="";
String S_UserName="";
String S_ArriveTime="";
try {
stmt = Con.createStatement();
Rs=stmt.executeQuery(Sql);
while (Rs.next())
{
S_MsgMatter=Rs.getString("MsgMatter");
S_UserName=Rs.getString("UserName");
S_ArriveTime=Rs.getString("ArriveTime");
S_MsgTable+="<tr><td>"+S_UserName+":给您传来一条"+S_MsgMatter+",时间:"+S_ArriveTime+"请返回页首查看.</td></tr>";
}
Rs.close();
stmt=null;
S_MsgTable+="</table>";
}catch(SQLException ex){
System.err.println("从消息提示表中查询当前人的数据,储过程错误:" + ex.getMessage());
}
return S_MsgTable;
}
//-----------------------从消息提示表中查询当前人是否有新的数据-----------------------------------
public int MsgNew(String S_CurUserID){
String Sql = "Select MsgMatter From V_MsgHint where UserID='"+S_CurUserID+"'";
ResultSet Rs = null;
int I_Count=0;
try {
stmt = Con.createStatement();
Rs=stmt.executeQuery(Sql);
while (Rs.next())
{
//I_Count=Rs.getInt("MsgMatter");
I_Count++;
}
Rs.close();
stmt=null;
}catch(SQLException ex){
System.err.println("从消息提示表中查询当前人是否有新的数据,储过程错误:" + ex.getMessage());
}
return I_Count;
}
//-------------------删除消息提示表中有关该用户的信息-------------------------------------------
public void Msg_Del(String S_CurUserID){
String strSql = null;
try {
strSql="{call Pr_DelMsgHint(?)}";
stmtProc=Con.prepareCall(strSql);
stmtProc.setString(1,S_CurUserID);
stmtProc.execute();
stmtProc.close();
stmtProc=null;
}catch(SQLException ex){
System.err.println("删除消息提示表中有关该用户的信息,储过程错误:" + ex.getMessage());
}
}

}
kaibinsj 2003-11-12
  • 打赏
  • 举报
回复
一个连接只能建立一个statement??
楼上此言何解???
我就建了两个照样用啊!
marymcl 2003-11-12
  • 打赏
  • 举报
回复
注意使用得statment是否恰当的关闭了
giftxi 2003-11-12
  • 打赏
  • 举报
回复
看看你配置的最大连接数,一个连接只能建立一个STATEMENT,你看看你程序里的STATEMENT是不是有问题,如果数据处理用事物进行处理,需要特别注意这一点。
op2618 2003-11-12
  • 打赏
  • 举报
回复
也许是没配好!

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧