fox

2019-04-21 23:01

好的,谢谢。

fox

2019-04-21 18:36

@Jfinal 关键是不能在 call 中内部关闭,否则在外部调用时获取不到结果集,提示connection已经为null了,所以我写了一个close方法,是在外部调用时把ResultList获取到时才调用此方法关闭的。


public Object call(Connection conn) throws SQLException {
// TODO Auto-generated method stub
try {
conn2=DbKit.getConfig("sql2000").getConnection();
proc=conn2.prepareCall("{call new_no_NEW(?,?)}");
proc.setString(1, "保养申请单");
proc.registerOutParameter(2, java.sql.Types.VARCHAR);
proc.execute();
newNo=proc.getString(2);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}finally{
conn2.close(); // 在call 回调中关闭,外部就获取不到结集了,有什么方法,即能在此关闭,外部又能获取到这个调用存储过程的结果集。
conn2=null;
}

fox

2019-04-21 15:48

@Jfinal callback.close() 是这个sqd_newno_Callback 回调类中定义的一个close方法,如下:


public class sqd_newno_Callback implements ICallback {

public String tecdh=null;
public String no=null;
private String newNo="";

CallableStatement proc=null;
Connection conn2;

@Override
public Object call(Connection conn) throws SQLException {
// TODO Auto-generated method stub
try {
conn2=DbKit.getConfig("sql2000").getConnection();
proc=conn2.prepareCall("{call new_no_NEW(?,?)}");
proc.setString(1, "保养申请单");
proc.registerOutParameter(2, java.sql.Types.VARCHAR);
proc.execute();
newNo=proc.getString(2);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}finally{

}

no=newNo;
return no;
}

public void close()
{
try {
proc.close();
conn2.close(); //测试发现这句注释掉就不报错
conn2=null;
System.out.println("conn close.");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}

fox

2019-04-21 12:44

@Jfinal 如果close掉报以下错误,我很多地方调用存储过程都是用这种方式,如何才能正确close,请指正,谢谢!

com.jfinal.plugin.activerecord.ActiveRecordException: java.sql.SQLException: connection holder is null
at com.jfinal.plugin.activerecord.Model.save(Model.java:457)
at com.demo.mech.UG_mach_service_record_WXBY.saveWx(UG_mach_service_record_WXBY.java:43)
at com.demo.mech.MechControll.wxByNo(MechControll.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.jfinal.aop.Invocation.invoke(Invocation.java:73)
at com.jfinal.plugin.activerecord.tx.Tx.intercept(Tx.java:77)

代码如下:
1. ---
public class sqd_newno_Callback implements ICallback {

public String tecdh=null;
public String no=null;
private String newNo="";

CallableStatement proc=null;
Connection conn2;

@Override
public Object call(Connection conn) throws SQLException {
// TODO Auto-generated method stub
try {
conn2=DbKit.getConfig("sql2000").getConnection();
proc=conn2.prepareCall("{call new_no_NEW(?,?)}");
proc.setString(1, "保养申请单");
proc.registerOutParameter(2, java.sql.Types.VARCHAR);
proc.execute();
newNo=proc.getString(2);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}finally{

}

no=newNo;
return no;
}

public void close()
{
try {
proc.close();
conn2.close(); //测试发现这句注释掉就不报错
conn2=null;
System.out.println("conn close.");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}

2. 调用处
dh=Mach_service_record_WXBY.dao.getNewNo();
flag=mach_service_record_WXBY.dao.saveWx(dh, dept, vSuper,vContent, rsn,opr,machNo);


3. getNewNo方法代码如下:

public String getNewNo()
{
String dh=null;
Mech_bysqd_newno_Callback callback=new Mech_bysqd_newno_Callback();
Db.execute(callback);
dh=callback.no;
callback.close(); // 在此处外部调用clolse
return dh;
}

fox

2019-04-20 13:20

又挂掉了,好的,我改试试。

fox

2019-04-19 18:31

public Object call(Connection conn) throws SQLException {
// TODO Auto-generated method stub
conn=DbKit.getConfig("sql2000").getConnection(); //
CallableStatement proc=conn.prepareCall("{call Sp_Find_x(?,?,?,?,?)}");
proc.setString(1, dt1);
proc.setString(2, dt2);
proc.setString(3, workno);

proc.executeQuery();

rs=proc.getResultSet();
conn=null;
return rs;
}

fox

2019-04-19 18:30

conn=DbKit.getConfig("sql2000").getConnection();

我这行代码有问题?

fox

2019-04-19 18:25

2019-04-19 17:54:08
[ERROR]-[Thread: http-nio-80-exec-6]-[com.jfinal.core.ActionHandler.handle()]: /mbslipjjf/find_day_output
com.jfinal.plugin.activerecord.ActiveRecordException: com.alibaba.druid.pool.DataSourceDisableException
at com.jfinal.plugin.activerecord.DbPro.execute(DbPro.java:734)
at com.jfinal.plugin.activerecord.DbPro.execute(DbPro.java:720)
at com.jfinal.plugin.activerecord.Db.execute(Db.java:501)
at com.demo.mouldcup.SlipMouldCupJJFControll.find_day_output(SlipMBJJFControll.java:210)
at sun.reflect.GeneratedMethodAccessor60.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.jfinal.aop.Invocation.invoke(Invocation.java:73)
at com.jfinal.core.ActionHandler.handle(ActionHandler.java:83)
at com.demo.common.MyContextPathHandler.handle(MyContextPathHandler.java:31)
at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:73)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:800)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:806)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
Caused by: com.alibaba.druid.pool.DataSourceDisableException
at com.alibaba.druid.pool.DruidDataSource.takeLast(DruidDataSource.java:1616)
at com.alibaba.druid.pool.DruidDataSource.getConnectionInternal(DruidDataSource.java:1218)
at com.alibaba.druid.pool.DruidDataSource.getConnectionDirect(DruidDataSource.java:1086)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1066)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1056)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:104)
at com.jfinal.plugin.activerecord.Config.getConnection(Config.java:203)
at com.demo.mouldcup.MouldCup_JJF_OutputCallback.call(MouldCup_JJF_OutputCallback.java:29)
at com.jfinal.plugin.activerecord.DbPro.execute(DbPro.java:732)
... 29 more

fox

2019-04-18 16:55

跟了一下,是可以被执行

fox

2019-04-18 16:32

fox

2019-03-20 10:31

已解决,原来是后台帐号后有空格造成,难道是Linux下检查比Windows服务下要严格点?

fox

2019-03-19 18:24

@JFinal 看哪个文件?

fox

2019-03-19 18:04

fox

2018-12-26 17:37

@JFinal 哈哈