当前位置: 技术问答>java相关
循环嵌套查询求助!!我能给的分数就这么多了,请大虾帮忙
来源: 互联网 发布时间:2015-01-31
本文导语: 外面的循环如下: /*显示计量点GridTable的方法开始*****************************************/ public void ShowGridMp(String mpsql) { clsGetValue clsgetvalue = new clsGetValue(); Vector vcHead_b = new Vector(); Vector vcRo...
外面的循环如下:
/*显示计量点GridTable的方法开始*****************************************/
public void ShowGridMp(String mpsql)
{
clsGetValue clsgetvalue = new clsGetValue();
Vector vcHead_b = new Vector();
Vector vcRow_b = new Vector();
ResultSet rsBrowse=null;
vcHead_b.addElement("所属厂站");
vcHead_b.addElement("电压等级");
vcHead_b.addElement("计量点名称");
vcHead_b.addElement("正向潮流");
vcHead_b.addElement("反向潮流");
vcHead_b.addElement("计量属性");
vcHead_b.addElement("线路属性");
vcHead_b.addElement("CT倍率");
vcHead_b.addElement("PT倍率");
mpsql = "select a.ps_no as ps_no,b.ps_name as ps_name,a.mp_id as mp_id,a.mp_name as mp_name,a.mp_voltage as mp_voltage,a.mp_pename as mp_pename,a.mp_nename as mp_nename," +
"a.mp_attr as mp_attr,a.mp_class as mp_class,a.mp_ct as mp_ct,a.mp_pt as mp_pt from power_station b,metering_point a where a.ps_no = b.ps_no " + mpsql;
try {
rsBrowse=conn.executeQuery(mpsql);
while (rsBrowse.next()){
Vector vcItem_b = new Vector();
int ps_no = rsBrowse.getInt("ps_no");
String ps_name = rsBrowse.getString("ps_name");
int mp_id = rsBrowse.getInt("mp_id");
String mp_name = rsBrowse.getString("mp_name");
int mp_voltage = rsBrowse.getInt("mp_voltage");
String mp_pename = rsBrowse.getString("mp_pename");
String mp_nename = rsBrowse.getString("mp_nename");
int mp_attr = rsBrowse.getInt("mp_attr");
int mp_class = rsBrowse.getInt("mp_class");
int mp_ct = rsBrowse.getInt("mp_ct");
int mp_pt = rsBrowse.getInt("mp_pt");
vcItem_b.addElement(ps_name);
vcItem_b.addElement(GetDictName("VLEVEL",mp_voltage));
vcItem_b.addElement(mp_name);
vcItem_b.addElement(mp_pename);
vcItem_b.addElement(mp_nename);
vcItem_b.addElement(clsgetvalue.GetDictName("MP_ATTR",mp_attr));
vcItem_b.addElement(clsgetvalue.GetDictName("MP_CLASS",mp_class));
vcItem_b.addElement(clsgetvalue.GetDictName("CT",mp_ct));
vcItem_b.addElement(clsgetvalue.GetDictName("PT",mp_pt));
System.out.println(mp_name);
vcRow_b.addElement(vcItem_b);
}//while (rsBrowse.next()){
rsBrowse.close();
}
catch(Exception ex) {
ex.printStackTrace();
}
clsTableMp = new clsTable(vcRow_b,vcHead_b);
clsTableMp.SortByCol(clsTableMp,"0000000000001111111111111");
jScrollPaneMpgrid.getViewport().add(clsTableMp,null);
}
/*显示计量点GridTable的方法结束*****************************************/
外面的循环调用的clsgetvalue.GetDictName方法:
/*返回各种数据字典表中枚举子段的显示值的方法开始*****************************************/
public String GetDictName(String dict_code,int dict_no)
{
String dispname = new String();
ResultSet rs = null;
String sql = new String();
sql = "select dict_name from enu_dict where dict_code = '" + dict_code + "'" + "and dict_no = '" + dict_no + "'";
try {
rs = conn.executeQuery(sql);
while (rs.next()){
dispname = rs.getString("dict_name");
}//while (rsBrowse.next()){
rs.close();
}
catch(Exception ex) {
ex.printStackTrace();
}
return dispname;
}
/*返回各种数据字典表中枚举子段的显示值的方法结束*****************************************/
外循环的查询出来的纪录有260多条,用System.out.print跟踪发现
到100多条就总是报错:
dbConnection_query.executeQuery:ORA-01000: 超出打开游标的最大数
具体出错的地方就是上面的clsgetvalue.GetDictName方法中的
while (rs.next()){
请问各位大虾,这是什么地方出的问题呢???
/*显示计量点GridTable的方法开始*****************************************/
public void ShowGridMp(String mpsql)
{
clsGetValue clsgetvalue = new clsGetValue();
Vector vcHead_b = new Vector();
Vector vcRow_b = new Vector();
ResultSet rsBrowse=null;
vcHead_b.addElement("所属厂站");
vcHead_b.addElement("电压等级");
vcHead_b.addElement("计量点名称");
vcHead_b.addElement("正向潮流");
vcHead_b.addElement("反向潮流");
vcHead_b.addElement("计量属性");
vcHead_b.addElement("线路属性");
vcHead_b.addElement("CT倍率");
vcHead_b.addElement("PT倍率");
mpsql = "select a.ps_no as ps_no,b.ps_name as ps_name,a.mp_id as mp_id,a.mp_name as mp_name,a.mp_voltage as mp_voltage,a.mp_pename as mp_pename,a.mp_nename as mp_nename," +
"a.mp_attr as mp_attr,a.mp_class as mp_class,a.mp_ct as mp_ct,a.mp_pt as mp_pt from power_station b,metering_point a where a.ps_no = b.ps_no " + mpsql;
try {
rsBrowse=conn.executeQuery(mpsql);
while (rsBrowse.next()){
Vector vcItem_b = new Vector();
int ps_no = rsBrowse.getInt("ps_no");
String ps_name = rsBrowse.getString("ps_name");
int mp_id = rsBrowse.getInt("mp_id");
String mp_name = rsBrowse.getString("mp_name");
int mp_voltage = rsBrowse.getInt("mp_voltage");
String mp_pename = rsBrowse.getString("mp_pename");
String mp_nename = rsBrowse.getString("mp_nename");
int mp_attr = rsBrowse.getInt("mp_attr");
int mp_class = rsBrowse.getInt("mp_class");
int mp_ct = rsBrowse.getInt("mp_ct");
int mp_pt = rsBrowse.getInt("mp_pt");
vcItem_b.addElement(ps_name);
vcItem_b.addElement(GetDictName("VLEVEL",mp_voltage));
vcItem_b.addElement(mp_name);
vcItem_b.addElement(mp_pename);
vcItem_b.addElement(mp_nename);
vcItem_b.addElement(clsgetvalue.GetDictName("MP_ATTR",mp_attr));
vcItem_b.addElement(clsgetvalue.GetDictName("MP_CLASS",mp_class));
vcItem_b.addElement(clsgetvalue.GetDictName("CT",mp_ct));
vcItem_b.addElement(clsgetvalue.GetDictName("PT",mp_pt));
System.out.println(mp_name);
vcRow_b.addElement(vcItem_b);
}//while (rsBrowse.next()){
rsBrowse.close();
}
catch(Exception ex) {
ex.printStackTrace();
}
clsTableMp = new clsTable(vcRow_b,vcHead_b);
clsTableMp.SortByCol(clsTableMp,"0000000000001111111111111");
jScrollPaneMpgrid.getViewport().add(clsTableMp,null);
}
/*显示计量点GridTable的方法结束*****************************************/
外面的循环调用的clsgetvalue.GetDictName方法:
/*返回各种数据字典表中枚举子段的显示值的方法开始*****************************************/
public String GetDictName(String dict_code,int dict_no)
{
String dispname = new String();
ResultSet rs = null;
String sql = new String();
sql = "select dict_name from enu_dict where dict_code = '" + dict_code + "'" + "and dict_no = '" + dict_no + "'";
try {
rs = conn.executeQuery(sql);
while (rs.next()){
dispname = rs.getString("dict_name");
}//while (rsBrowse.next()){
rs.close();
}
catch(Exception ex) {
ex.printStackTrace();
}
return dispname;
}
/*返回各种数据字典表中枚举子段的显示值的方法结束*****************************************/
外循环的查询出来的纪录有260多条,用System.out.print跟踪发现
到100多条就总是报错:
dbConnection_query.executeQuery:ORA-01000: 超出打开游标的最大数
具体出错的地方就是上面的clsgetvalue.GetDictName方法中的
while (rs.next()){
请问各位大虾,这是什么地方出的问题呢???
|
奇怪:rs = conn.executeQuery(sql)这句居然没报错?Connection有这个方法?
你用的JDK是什么版本的呢?JDBC的版本是怎么知道的?
建议:
1、安装最新的JDK和ORACLE的JDBC驱动……
2、一般写数据库连接类的时候把连接的动作写为一个方法比较好,象这样:
boolean connect(){
try {
Class.forName(driverName);
conn = DriverManager.getConnection (strUrl,username,password);
stmt = conn.createStatement();
}
catch (Exception ex) {
System.out.println("Err at connect(): " + ex);
return false;
}
return true;
}
你试试……
你用的JDK是什么版本的呢?JDBC的版本是怎么知道的?
建议:
1、安装最新的JDK和ORACLE的JDBC驱动……
2、一般写数据库连接类的时候把连接的动作写为一个方法比较好,象这样:
boolean connect(){
try {
Class.forName(driverName);
conn = DriverManager.getConnection (strUrl,username,password);
stmt = conn.createStatement();
}
catch (Exception ex) {
System.out.println("Err at connect(): " + ex);
return false;
}
return true;
}
你试试……
|
超出打开游标的最大数 的错误我以前遇到过,也曾折腾了我很久,最后我在oracle的新闻组也问了,他们给的回复是我要及时关闭用过的connection,我反复看代码才发现是我没能及时关闭不用的statement造成的。