简体   繁体   English

在jsp下未产生Oracle数据库查询

[英]Oracle database query has not result under jsp

I would like to retrieve the data in Oracle database. 我想在Oracle数据库中检索数据。 If I use jsp on Tomcat, it has not result, but if I use SQLDeveloper, the result is show. 如果我在Tomcat上使用jsp,则没有结果,但是如果使用SQLDeveloper,则显示结果。 Both sql string are equal. 两个sql字符串相等。

The sql string is: sql字符串是:

String q="SELECT pid, pswd, name, lgnpics FROM users WHERE pid='"+ uid + "' and pswd='" + psw + "'";

The connection, statement and the resultset realization is: 连接,语句和结果集实现为:

String cs = "jdbc:oracle:thin:@localhost:1521:xe";
Class.forName("oracle.jdbc.OracleDriver");
Connection cn = DriverManager.getConnection(cs, db_user, db_psw);
Statement stmt = cn.createStatement();
ResultSet rs = stmt.executeQuery(q);

If I test it, the resultset is not available, but I know it's a false result. 如果我对其进行测试,则结果集不可用,但我知道它是错误的结果。

The connection is ready and if I use a field which doesn't exixts, I get an error, so the statement is ready to use it. 连接已准备就绪,如果我使用的字段不存在问题,则会收到错误消息,因此该语句已准备就绪,可以使用它。

The header of the JSP file is: JSP文件的头是:

%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8" import="java.sql.*,java.io.*,java.util.*"
    session="true"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>

Could anybody help me why? 有人可以帮助我吗?

UPDATE1: The code what I test the result: UPDATE1:我测试结果的代码:

if (!rs.next()) {
    out.println("NOK: result set is not available");
} else {
    while (rs.next()) {
        out.write("OK: result is available");
    }
}

Thanks in advance. 提前致谢。

just try with this segment: 只需尝试以下部分:

 boolean more = rs.next(); if (!more) { out.println("NOK: result set is not available"); } else { while (more) { out.write("OK: result is available"); ....... more = rs.next(); } } 

because I believe you can use rs.next() only once as it points out the cursor asap you call it. 因为我相信您只能使用rs.next()一次,因为它会在您尽快调用它时指出光标。 so it won't reach your while() loop as it is already passed by your if() condition. 因此它不会到达while()循环,因为if()条件已经传递了它。

Try and see ! 尝试看看!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM