JiveJdon Community Forums
在线396人   首页   主题表   培训咨询   标签   精华   查搜   注册    登陆 RSS
首页 » 论坛 » Java多线程 集群 并行模式
???en_US.forumThreadPrev.name??? 上一主题
  Go back to the topic 返回本主题   Go back to the topic listing返回主题列表
???en_US.forumThreadNext.name??? 下一主题
Go 总共有 3 回复 / 1
 发表新帖子   回复该主题贴
chabulier

悄悄话
发表文章: 22
注册时间: 2004年08月18日 13:56
请教道友:Statement可否集成到连接池中? 2004年11月01日 13:23 到本帖网址 加入本帖到收藏夹 发送到手机 回复该主题
标签列表
开始在连接池管理类中定义了一个Statement属性,使用他来执行查询,结果发现如果查询方法不同步,则多个用户并发访问时,程序中又包含对结果集的操作,就会导致偶尔的取不到结果集,如果要求开发人员传入一个Connection自己创建一个Statement的话,关闭这个Statement就成了问题,请教各位道友各抒己见给个看法,本人刚学java,不知道这个想法是不是很可笑,谢谢了先
chabulier

悄悄话
发表文章: 22
注册时间: 2004年08月18日 13:56
Re: 请教道友:Statement可否集成到连接池中? 2004年11月01日 13:28 到本帖网址 加入本帖到收藏夹 发送到手机 回复该主题
如果同步这个方法肯定会大大影响性能,而不同步的话,现在的Singleton模式连接池管理类肯定会导致查询受阻,但是好像更新不太受影响,因为更新我们可以要求程序员传当前连接进来,自己生成Statement对象,完后关闭他.这个问题的需求是:希望程序员可以不用生成Statement,直接执行SQL语句.
chabulier

悄悄话
发表文章: 22
注册时间: 2004年08月18日 13:56
Re: 请教道友:Statement可否集成到连接池中? 2004年11月01日 15:56 到本帖网址 加入本帖到收藏夹 发送到手机 回复该主题


public ResultSet executeQuery(String querySQL, Connection con) throws SQLException
{
Connection conn = (Connection)con;
Statement st = conn.createStatement();
ResultSet rs = null;
try
{
rs = st.executeQuery(querySQL);
ResultSetAdapter rsAdapter = new ResultSetAdapter(rs);
ResultSetAdapter rsAdapterReturn = rsAdapter;
loghelper.info("executeQuery", "end");
return rsAdapterReturn;
}
catch (SQLException ex)
{
while(ex != null)
{
if (ex.getSQLState() !=null && ex.getSQLState().equals(
"40001"))
{
System.out.println(
"deadlock occur.");
}else if(ex.getSQLState() !=null && (ex.getSQLState().equals(
"40XL1") || ex.getSQLState().equals("40XL2")))
{
System.out.println(
"lockwait timeout.");
}
ex.printStackTrace();
ex = ex.getNextException();
}
loghelper.info(
"executeQuery", "end");
return null;
}
finally
{
// st.close();
}

}
chabulier

悄悄话
发表文章: 22
注册时间: 2004年08月18日 13:56
Re: 请教道友:Statement可否集成到连接池中? 2004年11月01日 16:01 到本帖网址 加入本帖到收藏夹 发送到手机 回复该主题

public ResultSet executeQuery(String querySQL, Connection con) throws SQLException
{
Connection conn = (Connection)con;
Statement st = conn.createStatement();
ResultSet rs = null;
try
{
rs = st.executeQuery(querySQL);
return rs;
}
catch (SQLException ex)
{
while(ex != null)
{
ex.printStackTrace();
ex = ex.getNextException();
}
return null;
}
finally
{
// here I can't use close() method
// st.close();
}

}
这个主题有 3 回复 / 1Go
???en_US.forumThreadPrev.name??? 上一主题
  Go back to the topic 返回本主题   Go back to the topic listing返回主题列表    返回页首返回页首
???en_US.forumThreadNext.name??? 下一主题
热点TAG: AOP cache 缓存 DDD EJB 集群 设计模式 Hibernate IOC JiveJdon OO RBAC Seam Spring Struts
正在读取,请等待...
google yahoo 新浪ViVi 365Key网摘 天极网摘 CSDN网摘 添加到百度搜藏 POCO网摘 博采网摘
查询本论坛内 回复超过的热门帖子
     回复该主题贴
标题
 
粗体 斜体 下划线 插入图片 插入代码 插入url链接 插入附件
内容
  发贴前查询 标签列表勿重复发表问题

RSS 手机阅读 add to google add to yahoo
解惑之道在J道 ,打造中国最具影响力的的企业软件社区
OpenSource JIVEJDON v3.0 Powered by JdonFramework Code © 2002-08 jdon.com
anti spam