日期:2014-05-18  浏览次数:20708 次

jsp和javaBean,导入对应的包,可说我的ResultSet对象没有定义?(源代码)
package com.shijian.shopping.util;
import java.sql.*;

public class DBConnect {
private Connection con = null;
private Statement st = null;
private PreparedStatement pst = null;
private ResultSet rs = null;

private void init(){
try{
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost/loginbean";
con = DriverManager.getConnection(url,"root","1986528");
}catch(ClassNotFoundException e){
e.printStackTrace();
}catch(SQLException e){
e.printStackTrace();
}
}

public DBConnect(){
try{
init();
st = con.createStatement();
}catch(SQLException e){
e.printStackTrace();
}
}

public DBConnect(String sql){
try{
init();
pst = con.prepareStatement(sql);
}catch(SQLException e){
e.printStackTrace();
}
}

public void executeQurey(String sql){
try{
if(st != null)
rs = st.executeQuery(sql);
}catch(SQLException e){
e.printStackTrace();
}
}

public void executeQurey(){
try{
if(pst != null)
rs = pst.executeQuery();
}catch(SQLException e){
e.printStackTrace();
}
}

public void executeUpdate(String sql){
try{
if(st != null)
st.executeUpdate(sql);
else
pst.executeUpdate(sql);
}catch(SQLException e){
e.printStackTrace();
}
}

//以下为PreparedStatement对象的赋值操作

public void setString(int parameterIndex, String x){
try {
pst.setString(parameterIndex, x);
} catch (SQLException e) {
e.printStackTrace();
}
}

public void setInt(int parameterIndex, int x){
try{
pst.setInt(parameterIndex, x);
}catch(SQLException e){
e.printStackTrace();
}
}

public void setDate(int parameterIndex, Date x){
try{
pst.setDate(parameterIndex, x);
}catch(SQLException e){
e.printStackTrace();
}
}

//以下为取值方法

public String getString(String x) throws SQLException{
return rs.getString(x);
}

public int getInt(String x) throws SQLException{
return rs.getInt(x);
}

public Date getDate(String x) throws SQLException{
return rs.getDate(x);
}

public void next(){
try{
rs.next();
}catch(SQLException e){
e.printStackTrace();
}
}

public void close(){
try{
if(rs != null)rs.close();
if(pst != null)pst.close();
if(st != null)st.close();
if(con != null)con.close();
}catch(SQLException e){
e.printStackTrace();
}
}
}


JSP代码:

<%@ page language="java" contentType="text/html; charset=GB18030"
  pageEncoding="GB18030"%>
<%@ page import="com.shijian.shopping.util.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>Insert title here</title>
</head>
<body>
<%
DBConnect db = new DBConnect();
String sql = "select * from datalogin where name = 'shijian'";
db.executeQurey(sql);
%>