我的程序错在哪里了? rs在Bean里的吗???写成workM.rs试一下. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 rs好象没定义吧.而且RS的值是怎么取来的?workM.rs = workM.executeQuery(strSQL);如果在BEAN里定义, 我的javabean是这样写的:package online;import java.sql.*;public class onlineconn1{ String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver"; String sConnStr = "jdbc:odbc:online"; Connection conn = null; ResultSet rs = null; private java.sql.Statement stmt = null; public onlineconn1() { try { Class.forName(sDBDriver); } catch(java.lang.ClassNotFoundException e) { System.err.println("onlineconn(): " + e.getMessage()); } } public ResultSet executeQuery(String sql) { rs = null; try { conn = DriverManager.getConnection(sConnStr); Statement stmt = conn.createStatement(); rs = stmt.executeQuery(sql); } catch(SQLException ex) { System.err.println("aq.executeQuery: " + ex.getMessage()); } return rs; } public void executeUpdate(String sql) { try { conn = DriverManager.getConnection(sConnStr); Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); stmt.executeUpdate(sql); } catch(SQLException ex) { System.err.println("aq.executeUpdate: " + ex.getMessage()); } } public void disconnectToDB() throws java.sql.SQLException{ if(rs!=null) { rs.close(); rs = null; } if(stmt!=null){ stmt.close(); stmt = null; } if(conn!=null) { conn.close(); conn = null; } }}jsp页面这样写还是报错不知道应该如何写?<%@ page contentType="text/html;charset=ISO8859_1"%><%@ page language="java"%><%@ page import="java.*"%><jsp:useBean id="workM" scope="page" class="online.onlineconn1" /><jsp:useBean id="workc" scope="page" class="online.ISOtoGb2312" /><%String name1=request.getParameter("name").trim(), key1=request.getParameter("key").trim(), strSQL;strSQL="select name,mkey from student where name='"+name1+"' and mkey='"+key1+"'";try{ workM.executeQuery(strSQL); if(!workM.rs.next()){ response.sendRedirect("stuloginerror.jsp"); } else{ response.sendRedirect("content.jsp"); workM.disconnectToDB(); } } catch(Exception ex){ out.print(ex.getMessage()); }%>报错内容为:An error occurred at line: -1 in the jsp file: nullGenerated servlet error: [javac] Since fork is true, ignoring compiler setting. [javac] Compiling 1 source file [javac] Since fork is true, ignoring compiler setting. [javac] D:\Tomcat 4\work\Standalone\localhost\test\online\stuloginform_jsp.java:82: rs is not public in online.onlineconn1; cannot be accessed from outside package [javac] if(!workM.rs.next()){ [javac] ^ [javac] 1 error rs is not public in online.onlineconn1; cannot be accessed from outside package呵呵,不能被访问,你还是把rs定义到jsp里吧 那我是不是也要改javabean啊没有别的办法了吗? 关于SSH,关于WEB开发,有空的都可以进来看看聊聊。 javascript变量获取的问题 S2hh配的sequence问题,疑惑中,解答对的200分送给他,谢谢了,在线等!!!!!!!!!!!!!! 求一本学JSP的优秀教材 现在搞java web开发主要用那些技术啊(散的分,大家来讨论一下啊!) Apache SOAP 的问题,谢谢! 高份请教高手,高手请劲 在JSP增加数据!! JSP程序员月薪 apache无发启动,help! 这句话什么意思? 怎样判断ResultSet中有没有记录??
而且RS的值是怎么取来的?
workM.rs = workM.executeQuery(strSQL);
如果在BEAN里定义,
package online;
import java.sql.*;
public class onlineconn1
{
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr = "jdbc:odbc:online";
Connection conn = null;
ResultSet rs = null;
private java.sql.Statement stmt = null;
public onlineconn1()
{
try {
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e)
{
System.err.println("onlineconn(): " + e.getMessage());
}
}
public ResultSet executeQuery(String sql)
{
rs = null;
try {
conn = DriverManager.getConnection(sConnStr);
Statement stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex)
{
System.err.println("aq.executeQuery: " + ex.getMessage());
}
return rs;
}
public void executeUpdate(String sql)
{
try {
conn = DriverManager.getConnection(sConnStr);
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
stmt.executeUpdate(sql);
}
catch(SQLException ex)
{
System.err.println("aq.executeUpdate: " + ex.getMessage());
}
}
public void disconnectToDB() throws
java.sql.SQLException{
if(rs!=null)
{
rs.close();
rs = null;
}
if(stmt!=null){
stmt.close();
stmt = null;
} if(conn!=null)
{
conn.close();
conn = null;
}
}
}jsp页面这样写还是报错不知道应该如何写?
<%@ page contentType="text/html;charset=ISO8859_1"%>
<%@ page language="java"%>
<%@ page import="java.*"%>
<jsp:useBean id="workM" scope="page" class="online.onlineconn1" />
<jsp:useBean id="workc" scope="page" class="online.ISOtoGb2312" />
<%
String name1=request.getParameter("name").trim(),
key1=request.getParameter("key").trim(),
strSQL;
strSQL="select name,mkey from student where name='"+name1+"' and mkey='"+key1+"'";
try{
workM.executeQuery(strSQL);
if(!workM.rs.next()){
response.sendRedirect("stuloginerror.jsp");
}
else{
response.sendRedirect("content.jsp");
workM.disconnectToDB();
}
}
catch(Exception ex){
out.print(ex.getMessage());
}
%>报错内容为:
An error occurred at line: -1 in the jsp file: nullGenerated servlet error:
[javac] Since fork is true, ignoring compiler setting.
[javac] Compiling 1 source file
[javac] Since fork is true, ignoring compiler setting.
[javac] D:\Tomcat 4\work\Standalone\localhost\test\online\stuloginform_jsp.java:82: rs is not public in online.onlineconn1; cannot be accessed from outside package
[javac] if(!workM.rs.next()){
[javac] ^
[javac] 1 error
呵呵,不能被访问,你还是把rs定义到jsp里吧