//数据库的操作
package beans;import java.sql.*;
import beans.Conn;public class DataBase {
protected Connection conn = null; //Connection接口
protected Statement stmt = null; //Statement接口
protected ResultSet rs = null; //记录结果集
protected PreparedStatement prepstmt = null; //PreparedStatement接口
protected String sqlStr; //sql String
protected boolean isConnect=true; //与数据库连接标识
public DataBase() {
try
{
sqlStr = "";
Conn dc = new Conn();
conn = dc.getConnection();
stmt = conn.createStatement();
}
catch (Exception e)
{
System.out.println(e);
isConnect=false;
}
} public Statement getStatement() {
return stmt;
} public Connection getConnection() {
return conn;
} public PreparedStatement getPreparedStatement() {
return prepstmt;
} public ResultSet getResultSet() {
return rs;
}
public String getSql() {
return sqlStr;
} public boolean execute() throws Exception {
return false;
} public boolean insert() throws Exception {
return false;
} public boolean update() throws Exception {
return false;
} public boolean delete() throws Exception {
return false;
}
public boolean query() throws Exception {
return false;
} public void close() throws SQLException {
if ( stmt != null )
{
stmt.close();
stmt = null;
}
conn.close();
conn = null;
}
/*public static void main(String args[])
{
DataBase test=new DataBase();
String sqlStr;
sqlStr="insert into Userlist(UserName,PassWord)values('shuang11','jie11')";//插入操作
//sqlStr="DELETE FROM Userlist";//把表中的所有数据都删除了
//sqlStr="delete Userlist where UserName='shuang'";//删除一条语句
try{
int stmt=test.stmt.executeUpdate(sqlStr);
ResultSet rs=test.stmt.executeQuery("select*from Userlist");
while(rs.next()){
System.out.print("名称: "+rs.getString(1));
System.out.print("\tpassword: "+rs.getString(2));
System.out.println();}
}
catch(Exception e){
e.printStackTrace();
}
}*///测试
}以上是我写的一个操作数据库的bean
但是一写到jsp里就提示说找不到符号
<%@ page import="java.sql.*" %>
<jsp:useBean id="test" scope="page" class="beans.DataBase"/>
<%
test.DataBase();
%>
报错的提示:找不到符号
符号: 方法 DataBase()
位置: 类 beans.DataBase
test.DataBase();
为什么找不到呢?人家不是定义的好好的吗?
package beans;import java.sql.*;
import beans.Conn;public class DataBase {
protected Connection conn = null; //Connection接口
protected Statement stmt = null; //Statement接口
protected ResultSet rs = null; //记录结果集
protected PreparedStatement prepstmt = null; //PreparedStatement接口
protected String sqlStr; //sql String
protected boolean isConnect=true; //与数据库连接标识
public DataBase() {
try
{
sqlStr = "";
Conn dc = new Conn();
conn = dc.getConnection();
stmt = conn.createStatement();
}
catch (Exception e)
{
System.out.println(e);
isConnect=false;
}
} public Statement getStatement() {
return stmt;
} public Connection getConnection() {
return conn;
} public PreparedStatement getPreparedStatement() {
return prepstmt;
} public ResultSet getResultSet() {
return rs;
}
public String getSql() {
return sqlStr;
} public boolean execute() throws Exception {
return false;
} public boolean insert() throws Exception {
return false;
} public boolean update() throws Exception {
return false;
} public boolean delete() throws Exception {
return false;
}
public boolean query() throws Exception {
return false;
} public void close() throws SQLException {
if ( stmt != null )
{
stmt.close();
stmt = null;
}
conn.close();
conn = null;
}
/*public static void main(String args[])
{
DataBase test=new DataBase();
String sqlStr;
sqlStr="insert into Userlist(UserName,PassWord)values('shuang11','jie11')";//插入操作
//sqlStr="DELETE FROM Userlist";//把表中的所有数据都删除了
//sqlStr="delete Userlist where UserName='shuang'";//删除一条语句
try{
int stmt=test.stmt.executeUpdate(sqlStr);
ResultSet rs=test.stmt.executeQuery("select*from Userlist");
while(rs.next()){
System.out.print("名称: "+rs.getString(1));
System.out.print("\tpassword: "+rs.getString(2));
System.out.println();}
}
catch(Exception e){
e.printStackTrace();
}
}*///测试
}以上是我写的一个操作数据库的bean
但是一写到jsp里就提示说找不到符号
<%@ page import="java.sql.*" %>
<jsp:useBean id="test" scope="page" class="beans.DataBase"/>
<%
test.DataBase();
%>
报错的提示:找不到符号
符号: 方法 DataBase()
位置: 类 beans.DataBase
test.DataBase();
为什么找不到呢?人家不是定义的好好的吗?
<jsp:useBean id="test" scope="page" class="beans.DataBase"/> 这个就已
以经帮你生成对象了..就这个test.向必去test.DataBase()在来一次了..
<jsp:useBean id="test" scope="page" class="beans.DataBase"/>这个已经帮你实例化了lz或者用import,或者不要通过构造函数取连接,构造函数用来初始化driver,url,user,password等参数就可以了
<% test.query("select *from Userlist"); %>
那换成这个样子之后还有错误:
无法将 beans.DataBase 中的 query() 应用于 (java.lang.String)
test.query("select *from Userlist");
帮助第一,互相交流,共同进步!记住:分享与贡献同等重要!