代码功能描述: 我从一个表中去查询了一系列数据,然后逐个将其中的某个字段值取出来(通过循环语句控制),然后再用一句查询语句来取出相应的值. 代码如下: Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc dbc:jspdata"); Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY); ResultSet rs = stmt.executeQuery("select * from ztgsj"); while(rs.next()) {String xm=rs.getString("xm"); String gzlbmc=rs.getString("lb"); String sql1="select xm,sfz from (tblrsxx inner join tblgzsj on tblgzsj.rybm=tblrsxx.rybm) where tblgzsj.gzlbmc = '"+gzlbmc+"' and xm='"+xm+"'"; Statement stmt1 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY); ResultSet rs1 = stmt1.executeQuery(sql1);if (rs1.next()) { String xm1=rs1.getString("xm"); String sfzh1=rs1.getString("sfz");}
} 其中去除掉红色部分运行正常,但有红色部分后报告xm1,sfzh1重复定义,这样的语句应该怎么写才对? 谢谢大家. |