|  | 
 
 楼主|
发表于 2004-10-17 15:17:04
|
显示全部楼层 
| 突然想到Tomcat4.1.30还没删,就把这堆东西拿过去,一试,跑的跟上了油一样。不解   
 先将就着在4.1.30里跑吧。想把以前做的数据库操作器改成带连接池的,结果总出现连接被提前关闭的异常,而异常是由套在最底层的bean产生的,追查起来真麻烦。
 
 现在,基本上追查到这个错误产生的位置了,但是不知道如何解决。
 
 这个bean用于把结果集的输出变成HTML表格,以方便显示。它接收上级一个bean传过来的结果集,返回处理后的字符串、处理状态号、提示和产生的异常。
 
 bean的代码如下:
 [code:1]
 /**
 Instruction:
 A bean to convert the "ResultSet" into a Table for html after SQL-selecting. Uses && provides TFW-Standard-Interface.
 return 0: Every thing goes on well.
 return 1: Exception somewhere.
 return 2: Exception while input or output.
 return 3: Exception caused by no class or no file found.
 return 4: Exception with SQL.
 New version modified much, still need to do futher test.
 
 介绍:
 一个把SQL查询“结果集”变成字html表格的组件。使用和提供TFW标准接口。
 返回0: 一切正常。
 返回1:有地方异常。
 返回2: 有输入输出异常。
 返回3: 有文件或类未找到的异常。
 返回4: SQL操作异常。
 新版本改动很大,还需要进一步测试。
 
 Guide:
 "deal(ResultSet rs)".
 package AA.BB...NN;Use this while package in pack "AA.BB...NN". Attention, the pack must be placed in one of the "CLASSPATH"s.
 
 指引:
 “deal(ResultSet rs)”。
 package AA.BB...NN;
 如果要打到 “AA.BB...NN” 包里,就添加这些。注意,包必须放置在其中一处“CLASSPATH”下。
 */
 
 package jsp_db_oprt;
 
 import java.lang.*;
 import java.sql.*;
 
 public class RS_deal_3
 {
 //>>Put out.
 private static int stat=0;
 private static String text="";
 private static String str_out="";
 private static Exception excp_rtn=null;
 //<<Put out.
 
 //>>Get in.
 private static int mode=0;
 private static char LG='E';
 private static int GUI=0;
 //<<Get in.
 
 public static int rs_deal(ResultSet rs)
 {
 String string_1="[Start public static String deal()]";
 String string_2="[Ended public static String deal()]";
 
 System.out.println(string_1);
 System.out.println(" <Version: 0.9.1+ Alpha 2004-10-17-02>\n -- Provide TFW-Standard-Interface.\n -- Set NULL after useing.\n -- Connection-Pool testing ...");
 
 stat=0;
 text="";
 str_out="";
 excp_rtn=null;
 
 int i1,i2,i3;
 i1=i2=i3=0;
 
 ResultSetMetaData rsmd=null;
 int numbCols=0;
 String nameCols="";
 
 String l_s="<tr>";//line_start
 String l_e="</tr>";//line_ended
 String c_s="<td>";//colum_start
 String c_e="</td>";//colum_ended
 String s1="";
 String s2="";
 
 try
 {
 rsmd=rs.getMetaData();
 numbCols=rsmd.getColumnCount();
 System.out.println("001 ... OK");
 System.out.println("Number of colums in this table is: "+numbCols);
 i1=1;s2=l_s;
 while(i1<=numbCols)
 {
 s1=rsmd.getColumnName(i1);
 s2=s2+c_s+s1+c_e;
 //System.out.print("\t"+s1);
 i1++;
 System.out.println("002 ... OK");
 }
 System.out.println("003 ... OK");
 s2=s2+l_e;
 System.out.println("004 ... OK");
 System.out.println(s2);
 //System.out.print("\n");
 //System.out.print("\n");
 
 System.out.println("005 ... OK");
 while(rs.next())
 {
 System.out.println("006 ... OK");
 i1=1;
 s2=s2+l_s;
 while(i1<=numbCols)
 {
 s1=rs.getString(i1);
 s2=s2+c_s+s1+c_e;
 //System.out.print("\t"+s1);
 i1++;
 }
 s2=s2+l_e;
 //System.out.print("\n");
 }
 System.out.println("007 ... OK");
 
 s1="<table>"+s2+"</table>";
 
 rs.close();
 }
 catch(SQLException e1)
 {
 excp_rtn=e1;stat=4;
 //System.out.println("Exception caught: "+excp_rtn);
 }
 
 rsmd=null;
 rs=null;
 
 str_out=s1;
 //System.out.println(str_out);
 
 System.out.println(string_2);
 return stat;
 }
 
 public static String notice()
 {
 String string_1="[Start public static String notice()]";
 String string_2="[Ended public static String notice()]";
 System.out.println(string_1);
 
 if(stat==0)
 {
 text="Every thing goes on well.";
 }
 else if(stat==2)
 {
 text="Exception while input or output.";
 }
 else if(stat==3)
 {
 text="Exception caused by no class or no file found.";
 }
 else if(stat==4)
 {
 text="Exception with SQL.";
 }
 else
 {
 text="Exception somewhere.";
 }
 
 System.out.println(string_2);
 return text;
 }
 
 public static String result()
 {
 String string_1="[Start public static ResultSet result()]";
 String string_2="[Ended public static ResultSet result()]";
 System.out.println(string_1);
 System.out.println(string_2);
 return str_out;
 }
 
 public static Exception exception()
 {
 String string_1="[Start public static Exception exception()]";
 String string_2="[Ended public static Exception exception()]";
 System.out.println(string_1);
 System.out.println("Exception caught: "+excp_rtn);
 System.out.println(string_2);
 return excp_rtn;
 }
 }
 [/code:1]
 
 一个使用连接池的上级bean调用这个bean时在“/opt/prog/m/Tomcat/log/catalina.out”里生成的相关部分记录为:
 [code:1]
 [Start public static String deal()]
 <Version: 0.9.1+ Alpha 2004-10-17-02>
 -- Provide TFW-Standard-Interface.
 -- Set NULL after useing.
 -- Connection-Pool testing ...
 001 ... OK
 Number of colums in this table is: 3
 002 ... OK
 002 ... OK
 002 ... OK
 003 ... OK
 004 ... OK
 <tr><td>uid</td><td>truename</td><td>nikname</td></tr>
 005 ... OK
 [Ended public static String deal()]
 [Start public static String notice()]
 [Ended public static String notice()]
 [Start public static ResultSet result()]
 [Ended public static ResultSet result()]
 [Start public static Exception exception()]
 Exception caught: Connection is closed.  Operation is not permitted.
 [Ended public static Exception exception()]
 STATU:
 4
 NOTICE:
 Exception with SQL.
 EXCEPTION:
 Connection is closed.  Operation is not permitted.
 [Ended public static int bridge()]
 [Start public static String result()]
 [Ended public static String result()]
 [Start public Exception exception()]
 Exception caught: Connection is closed.  Operation is not permitted.
 [Ended public Exception exception()]
 [/code:1]
 
 而一个不使用连接池的上级bean同样也调用这个bean却一切正常,在“/opt/prog/m/Tomcat/log/catalina.out”里生成的相关部分记录为:
 [code:1]
 [Start public static String deal()]
 <Version: 0.9.1+ Alpha 2004-10-17-02>
 -- Provide TFW-Standard-Interface.
 -- Set NULL after useing.
 -- Connection-Pool testing ...
 001 ... OK
 Number of colums in this table is: 3
 002 ... OK
 002 ... OK
 002 ... OK
 003 ... OK
 004 ... OK
 <tr><td>uid</td><td>gid</td><td>passwd</td></tr>
 005 ... OK
 006 ... OK
 006 ... OK
 006 ... OK
 006 ... OK
 006 ... OK
 007 ... OK
 [Ended public static String deal()]
 [Start public static String notice()]
 [Ended public static String notice()]
 [Start public static ResultSet result()]
 [Ended public static ResultSet result()]
 [Start public static Exception exception()]
 Exception caught: null
 [Ended public static Exception exception()]
 [/code:1]
 | 
 |