小弟用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())
{
out.print("user name:");
out.print(rs.getString("name")+"password:");
out.print(rs.getString("pwd"));
}
rs.close();
stmt.close();
con.close();
}
%>
</body>
</html>
帮忙看看那里的问题.
/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())
{
out.print("user name:");
out.print(rs.getString("name")+"password:");
out.print(rs.getString("pwd"));
}
rs.close();
stmt.close();
con.close();
}
%>
</body>
</html>
帮忙看看那里的问题.
解决方案 »
- s2si
- 求教服务器项目访问问题
- EasyJF、SpringSide、Appfuse哪个好?
- 求助!!!从servlet请求转发到jsp后,原本有效的css样式表,失效了,高手帮帮我
- 同样关于usebean,希望有人可以帮我!
- 一个路径映射到多个Servlet上,提交时,是哪个Servlet处理请求?
- jsp通过数据库验证用户名和密码
- 急:刚刚装上tomcat,运行SERVLET没问题,但是JSP不行。。。
- 编译时为什么找不到javax.ejb.EJBObject?高分,解决后一定给!
- javamail发送邮件 选择附件错误 java.io.FileNotFoundException: Source
- 请前辈指路,活不下去了.
- 关于JSP中使用OCX控件的问题--急
说错 了
是应该加上包名DeepTeach.ConnDB