JDBC连接数据库 ,我要创建两条sql语句怎么办?

<scriptlanguage="javascript"type="text/javascript"><%Connectionconn=null;ResultSetrs=... <script language="javascript" type="text/javascript">
<% Connection conn = null;
ResultSet rs = null;
PreparedStatement ps = null;
String sql = "select BC_ID,NAME,FID from JY_BUSINESS_CATEGORY where LEVELS=2";
conn = DBConnect.getConn();
ps = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
rs = ps.executeQuery();
int i = 0;%>
var arrData=new Array();
<%while (rs.next()) {%>
arrData[<%=i%>]=new Array("<%=rs.getString("NAME")%>","<%=rs.getString("FID")%>","<%=rs.getString("BC_ID")%>");
<%i++;
}
rs.close();
ps.close();
conn.close();%></script>
===============================================
<script type="text/javascript">

<% Connection conn1 = null;
ResultSet rs1 = null;
PreparedStatement ps1 = null;
String sql1 = "select BC_ID,NAME,FID from JY_BUSINESS_CATEGORY where LEVELS=3";
conn1 = DBConnect.getConn();
ps1 = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
rs1 = ps1.executeQuery();
int j = 0;%>
var arrData1=new Array();
<%while (rs1.next()) {%>
arrData1[<%=j%>]=new Array("<%=rs1.getString("NAME")%>","<%=rs1.getString("FID")%>","<%=rs1.getString("NAME")%>");
<%j++;
}
rs1.close();
ps1.close();
conn1.close();%></script>
这样写的话 报 java.sql.SQLException: 关闭的连接这个错误 该怎么写?
展开
 我来答
百度网友60ba0a5
2012-04-17 · TA获得超过231个赞
知道小有建树答主
回答量:544
采纳率:100%
帮助的人:209万
展开全部
你定义的Connection conn1 = null;
但是你在使用ps1 = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE,
conn conn1不知道是不是这里错误,你看下
YugOppop6QSJ0
2012-04-17 · TA获得超过425个赞
知道小有建树答主
回答量:233
采纳率:0%
帮助的人:201万
展开全部
<script language="javascript" type="text/javascript">
<% Connection conn = null;
ResultSet rs = null;
PreparedStatement ps = null;
String sql = "select BC_ID,NAME,FID from JY_BUSINESS_CATEGORY where LEVELS=2";
conn = DBConnect.getConn();
ps = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
rs = ps.executeQuery();
int i = 0;%>
var arrData=new Array();
<%while (rs.next()) {%>
arrData[<%=i%>]=new Array("<%=rs.getString("NAME")%>","<%=rs.getString("FID")%>","<%=rs.getString("BC_ID")%>");
<%i++;
}
rs.close();
ps.close();
//这里不要关conn.close();%></script>
===============================================
<script type="text/javascript">

<% //这里不需要 Connection conn1 = null;
ResultSet rs1 = null;
PreparedStatement ps1 = null;
String sql1 = "select BC_ID,NAME,FID from JY_BUSINESS_CATEGORY where LEVELS=3";
//不需要conn1 = DBConnect.getConn();
ps1 = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
rs1 = ps1.executeQuery();
int j = 0;%>
var arrData1=new Array();
<%while (rs1.next()) {%>
arrData1[<%=j%>]=new Array("<%=rs1.getString("NAME")%>","<%=rs1.getString("FID")%>","<%=rs1.getString("NAME")%>");
<%j++;
}
rs1.close();
ps1.close();
//conn1.close();
conn.close();%></script>
一个Connection可以干好多事情的 而且很占资源 不要重复的去开于关
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式