<%!
String result = " ";
private void showTree ( int id , Statement stmt) {
try {
ResultSet rs = stmt.executeQuery("select * from article where pid =" + id);
while ( rs.next() ) {
result += "<tr><td>"+rs.getInt("id")+"</td><td>"+rs.getString("title")+"</td></tr>";
if ( rs.getInt("isleaf") != 0 ) {
showTree( rs.getInt("id"), stmt );
}
}
} catch ( SQLException e ) {
e.printStackTrace();
}
}private void showTree ( int id , Connection conn) {
try {
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from article where pid =" + id);
while ( rs.next() ) {
result += "<tr><td>"+rs.getInt("id")+"</td><td>"+rs.getString("title")+"</td></tr>";
if ( rs.getInt("isleaf") != 0 ) {
showTree( rs.getInt("id"), conn );
}
}
} catch ( SQLException e ) {
e.printStackTrace();
}
}
%>以上在两个方法你们觉得运行结果会一样吗??、 `````<%
Class.forName("oracle.jdbc.driver.OracleDriver");
String connStr = "jdbc:oracle:thin:@localhost:1521:orcl";
Connection conn = DriverManager.getConnection( connStr ,"scott","tiger" );
// "jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger"
Statement stmt = conn.createStatement(); ResultSet rls = stmt.executeQuery("select * from article where pid = 0 ");
while ( rls.next() ) {
result += "<tr><td>"+rls.getInt("id")+"</td><td>"+rls.getString("title")+"</td></tr>";
if ( rls.getInt("isleaf") != 0 ) {
showTree ( rls.getInt("id") , stmt );
//showTree ( rls.getInt("id") , conn );
}
}
%>
运行后结果不一样,怎么回事~!!!!奇怪~!!用传入Connection conn 的方法
用传入Statement stmt的方法:
感觉Statement stmt被多次调用时 Resultset rs 被改变了, 但是不可能这样。 我在另一个测试中试过没问题, 是不是递归的问题引起??? 好奇怪,明明应该是一样的JavaOracle
String result = " ";
private void showTree ( int id , Statement stmt) {
try {
ResultSet rs = stmt.executeQuery("select * from article where pid =" + id);
while ( rs.next() ) {
result += "<tr><td>"+rs.getInt("id")+"</td><td>"+rs.getString("title")+"</td></tr>";
if ( rs.getInt("isleaf") != 0 ) {
showTree( rs.getInt("id"), stmt );
}
}
} catch ( SQLException e ) {
e.printStackTrace();
}
}private void showTree ( int id , Connection conn) {
try {
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from article where pid =" + id);
while ( rs.next() ) {
result += "<tr><td>"+rs.getInt("id")+"</td><td>"+rs.getString("title")+"</td></tr>";
if ( rs.getInt("isleaf") != 0 ) {
showTree( rs.getInt("id"), conn );
}
}
} catch ( SQLException e ) {
e.printStackTrace();
}
}
%>以上在两个方法你们觉得运行结果会一样吗??、 `````<%
Class.forName("oracle.jdbc.driver.OracleDriver");
String connStr = "jdbc:oracle:thin:@localhost:1521:orcl";
Connection conn = DriverManager.getConnection( connStr ,"scott","tiger" );
// "jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger"
Statement stmt = conn.createStatement(); ResultSet rls = stmt.executeQuery("select * from article where pid = 0 ");
while ( rls.next() ) {
result += "<tr><td>"+rls.getInt("id")+"</td><td>"+rls.getString("title")+"</td></tr>";
if ( rls.getInt("isleaf") != 0 ) {
showTree ( rls.getInt("id") , stmt );
//showTree ( rls.getInt("id") , conn );
}
}
%>
运行后结果不一样,怎么回事~!!!!奇怪~!!用传入Connection conn 的方法
用传入Statement stmt的方法:
感觉Statement stmt被多次调用时 Resultset rs 被改变了, 但是不可能这样。 我在另一个测试中试过没问题, 是不是递归的问题引起??? 好奇怪,明明应该是一样的JavaOracle
解决方案 »
- 在java中向CICS客户端发送消息报IOException。
- 在displaytag中 我想判断(c:if)某一列是否为0,为0则不显示 不为0则显示其值 要怎么实现
- struts2中<s:if>标签的test表达式怎么用action传来的属性值?
- EJB 3.1内嵌容器 EJBContainer 测试
- 关于Struts2和 Jquery的结合问题
- Service中使用java反射的问题
- struts中的动态actionform
- json map 解析
- 求教JbuilderX+WebSphere5.1的集成方法,目前的JBX不支持5.1呀,怎么配?
- 安装好了J2EESDK1。4后怎样运行JAVA程序?
- struts用来做首页时,怎么写ACTION?
- 问个很弱智的问题?JSP是不是真的不能用?
在默认情况下,同一时间每个 Statement 对象在只能打开一个 ResultSet 对象。因此,如果读取一个 ResultSet 对象与读取另一个交叉,则这两个对象必须是由不同的 Statement 对象生成的。如果存在某个语句的打开的当前 ResultSet 对象,则 Statement 接口中的所有执行方法都会隐式关闭它。目测LZ的查询结果中有2个叶子节点,由于第二个showTree每次都创建了新的Statement,所以出现了上面的结果