C3p0的问题

ZiSheng 2019-03-11 11:12:11
获取数据源的类:JdbcUtils
public class JdbcUtils {

private static ComboPooledDataSource dataSource = null;
static{
//dataSource资源只能初始化一次
//dataSourceMysql = new ComboPooledDataSource("MySqlPDJH");
ModifyLogLevel.modifyInfoLevel(Level.ALL);
try {
XMLPaser xmlPaser = new XMLPaser(System.getProperty("user.dir")+"\\config\\config.xml");
String userString = "paidui";
String passwordString = "paidui";
String driverClassString = xmlPaser.getString("driverClass");
String jdbcUrlString = xmlPaser.getString("jdbcUrl");
dataSource = new ComboPooledDataSource();
dataSource.setUser(userString);
dataSource.setPassword(passwordString);
dataSource.setDriverClass(driverClassString);
dataSource.setJdbcUrl(jdbcUrlString);
//dataSource.setAcquireIncrement(5);
dataSource.setAcquireIncrement(xmlPaser.getInt("AcquireIncrement"));
dataSource.setInitialPoolSize(xmlPaser.getInt("InitialPoolSize"));
dataSource.setMinPoolSize(xmlPaser.getInt("MinPoolSize"));
dataSource.setMaxPoolSize(xmlPaser.getInt("MaxPoolSize"));
dataSource.setMaxStatements(xmlPaser.getInt("MaxStatements"));
dataSource.setMaxStatementsPerConnection(xmlPaser.getInt("MaxStatementsPerConnection"));
dataSource.setMaxIdleTime(xmlPaser.getInt("MaxIdleTime"));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* 获取连接
* @return
* @throws SQLException
*/
public static Connection getConnection(){
Connection conn = null;
try {
conn = dataSource.getConnection();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return conn;
}
}
ManipulateQueue


public class ManipulateQueue {
Connection conn = null;

PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "";
final String TB_NAME = "t_queue";

public ManipulateQueue() {
super();
// TODO Auto-generated constructor stub
}

/**
* 依据一定的排序得到前若干个记录
* @param constrain
* @param start
* @param end
* @return
*/
public List<MetaQueue> getQueue(String constrain,int start,int end){
List<MetaQueue> lmq= new ArrayList<MetaQueue>();
conn = JdbcUtils.getConnection();
sql = "Select 挂号NO,序号,状态,姓名,门诊号,诊间编码,登记时间,发生时间,type From "
+ "( SELECT A.*, ROWNUM RN FROM (SELECT * FROM "+this.TB_NAME+" where 1=1 "+constrain+") A WHERE ROWNUM <= "+end+" ) WHERE RN >="+start;
try {
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();//pstmt.execute();//pstmt.executeQuery();
while (rs.next()) {
int i=1;
MetaQueue objMetaQueue = new MetaQueue();
objMetaQueue.setGuaHao_NO(rs.getString(i++));
objMetaQueue.setXuHao(rs.getInt(i++));
objMetaQueue.setZhuangTai(rs.getInt(i++));
objMetaQueue.setXingMing(rs.getString(i++));
objMetaQueue.setMenZhenHao(rs.getString(i++));
objMetaQueue.setZhenJianBianMa(rs.getString(i++));
objMetaQueue.setDengJiShiJian(rs.getTimestamp(i++));
objMetaQueue.setFaShengShiJian(rs.getTimestamp(i++));
objMetaQueue.setType(rs.getInt(i++));
lmq.add(objMetaQueue);
}
} catch (Exception e) {
// TODO: handle exception
}finally{
close();
}
return lmq;
}


//关闭连接点
public void close() {
try {
if (rs != null) {
rs.close();
}
if (pstmt != null){
pstmt.close();
}
if(conn != null) {
conn.close();
}
} catch (SQLException e){
e.printStackTrace();
}
}

public static void main(String[] args) {
ManipulateQueue objManipulateQueue = new ManipulateQueue();
for(int i=1;i<100000;i++){
List<MetaQueue> lmq = new ArrayList<MetaQueue>();
lmq = objManipulateQueue.getQueue(" and 发生时间>to_date('2019-03-11','YYYY-MM-DD')", 1, 5);
for(MetaQueue objMetaQueue:lmq){
System.out.println(objMetaQueue.getXingMing());
}
}
//objManipulateQueue.delete(" and 发生时间<To_Date('"+CalendarUtil.getToday()+"','YYYY-MM-DD')");
}
}

问题:偶尔会出现这样的提示:
Exception in thread "Timer-2" java.lang.InternalError: Marking a ResultSet inactive that we did not know was opened!
at com.mchange.v2.c3p0.impl.NewPooledConnection.markInactiveResultSetForStatement(NewPooledConnection.java:353)
at com.mchange.v2.c3p0.impl.NewProxyResultSet.close(NewProxyResultSet.java:844)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.close(NewProxyPreparedStatement.java:1693)
at com.pdjh_no_fen_zhen.Manipulate.ManipulateQueue.close(ManipulateQueue.java:212)
at com.pdjh_no_fen_zhen.Manipulate.ManipulateQueue.getQueue(ManipulateQueue.java:151)
at com.pdjh_no_fen_zhen.xspHManager.MissionCall.run(MissionCall.java:57)
at java.util.TimerThread.mainLoop(Unknown Source)
at java.util.TimerThread.run(Unknown Source)


非常感谢!!!
...全文
261 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
ZiSheng 2019-03-12
  • 打赏
  • 举报
回复
找到原因了,是网络交换机的口有问题,换了一个之后没再出问题。
tianfang 2019-03-11
  • 打赏
  • 举报
回复
什么年代了 为什么还要用c3p0
qybao 2019-03-11
  • 打赏
  • 举报
回复
连接池多大啊?xmlPaser.getInt("MaxPoolSize")
是不是从连接池里取到的连接conn = dataSource.getConnection(); 有可能已经被你close 了conn.close();或者已经timeout了xmlPaser.getInt("MaxIdleTime")

67,511

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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