小鸟问个有关bean连接数据库的问题!
小弟用jsp用bean连接数据库报错:
/sql/sql.jsp(6,0) The value for the useBean class attribute ConnDB is invalid.
实再不知道那里有问题,请各位大侠帮帮小鸟.对你们来说很简单。
bean的代码如下:
package DeepTeach;
import java.sql.*;
public class ConnDB
{
String driver = "org.gjt.mm.mysql.Driver ";
String url= "jdbc:mysql://localhost:3306/mydata1?characterEncoding=GB2312 ";
String user= "root ";
String password= "123456 ";
Connection con=null;
ResultSet rs=null;
public ConnDB()
{
try
{
Class.forName(driver);
}
catch(
ClassNotFoundException e)
{
System.out.println(e.getMessage());
}
}
public void executeInsert(String sql)
{
try
{
Connection con=DriverManager.getConnection(url,user,password);
Statement stmt=con.createStatement();
stmt.executeUpdate(sql);
ResultSet rs=stmt.executeQuery( "select * from book ");
}
catch(
SQLException ex)
{
System.out.println( "sql.excuteUpdate: "+ex.getMessage());
}
}
}
调用bean的页面代码:
<%@page pageEncoding= "GB2312 "%>
<%@page contentType= "text/html; charset=gb2312 "%>
<%request.setCharacterEncoding( "GB2312 ");%>
<%@page import= "java.sql.* "%>
<jsp:useBean id= "cctv " class= "ConnDB " scope= "page "/>
<html>
<body>
<%
String name,pwd;
name=request.getParameter( "name ");
pwd=request.getParameter( "pwd ");
String sql= "insert into book values( ' "+name+ " ', ' "+pwd+ " ') "
int ok=cctv.executeInsert(sql);
if(int> 0)
{
while(rs.next())
{