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: 关闭的连接这个错误 该怎么写? 展开
<% 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: 关闭的连接这个错误 该怎么写? 展开
2个回答
展开全部
<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可以干好多事情的 而且很占资源 不要重复的去开于关
<% 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可以干好多事情的 而且很占资源 不要重复的去开于关
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询