javabean里的sql无法运行,请指教!!!

zl13 2004-08-26 10:18:14
javabean的代码:

package Mysqltest;
import java.sql.*;
public class DBconn
{
String DBDriver = "org.gjt.mm.mysql.Driver";
String ConnStr = "jdbc:mysql://localhost:3306/intov";
String MyUser = "root";
String MyPassword = " ";
Connection conn = null;
ResultSet rs = null;
public DBconn()
{
try
{
Class.forName(DBDriver);
}

catch(java.lang.ClassNotFoundException e)
{
System.err.println("DBconn():" + e.getMessage());
}
}

public ResultSet executeQuery(String sql)

{
rs = null;
try
{conn = DriverManager.getConnection(ConnStr,MyUser,MyPassword);
Statement stmt = conn.createStatement();
rs = stmt.executeQuery(sql);

}
catch(SQLException ex)
{
System.err.println("aq.executeQuery:" + ex.getMessage());
}
return rs;
}
}

jsp页面的代码:
<%@ page contentType="text/html; charset=gb2312" %>
<html>
<head>
<title>连接数据库</title>
</head>
<body>
<%@ page language="java" import="java.sql.*" %>
<jsp:useBean id="DBconn1" scope="page" class="Mysqltest.DBconn" />
<%
ResultSet Rs = DBconn1.executeQuery("Select * from web_bigclass");
while (Rs.next())
{
out.print("<h1>" + Rs.getString("bigClass") + "</h1>");
}

Rs.close();
%>

</body>
</html>

一运行-->ResultSet Rs = DBconn1.executeQuery("Select * from web_bigclass");就不行,高不懂!!!
...全文
77 点赞 收藏 15
写回复
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhaofan81 2004-08-26
应该jsp文件布署的问题吧
我以前也遇到过
后来找了个例子,把自己的文件拷过去(把原来的文件覆盖掉),结果可以了,呵呵....
不妨试一下
回复
zl13 2004-08-26
我的类就是放在WEB-INF/classes/Mysqltest下的
回复
zmybest 2004-08-26
如果是jar文件放WEB-INF/lib目录里
回复
Jzealot 2004-08-26
准确的说,编译的类应放在WEB-INF/classes/Mysqltest内,
而mysql驱动只需放在Tomcat的common\lib目录内
回复
haoming0 2004-08-26
设置以下path和classpath就行了
回复
haoming0 2004-08-26
设置以下path就行了
回复
haoming0 2004-08-26
你的类要放在WEB-INF/classes/Mysqltest/里才行!
回复
zl13 2004-08-26
DBconn():org.gjt.mm.mysql.Driver
aq.executeQuery:No suitable driver

tomcat出现了这样的错误,是不是应为我得mysql驱动没有放在jdk里只放在了tomcat里造成的?
回复
Jzealot 2004-08-26
很明显是没有找你到你写的类,看看你是不是放到WEB-INF/classes/里面的
回复
zl13 2004-08-26
自己顶一下
回复
haoming0 2004-08-26
你编译了吗?
编译完了,放那里了?
回复
zl13 2004-08-26
skyboy0720(敏,等你回来拿礼物!) :
java.lang.NullPointerException
at org.apache.jsp.javabeantest$jsp._jspService(javabeantest$jsp.java:94)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:201)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:381)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:473)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2347)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:468)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1027)
at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1125)
at java.lang.Thread.run(Thread.java:536)

就报这个错误
回复
zl13 2004-08-26
haoming0(龙啸冰河):
不行啊,还报错呢
org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.

D:\Program Files\Apache Tomcat 4.0\work\Standalone\localhost\_\website\javabeantest$jsp.java:3: Class or interface declaration expected.
import java.sql.*;Mysqltest.*;
^

D:\Program Files\Apache Tomcat 4.0\work\Standalone\localhost\_\website\javabeantest$jsp.java:10: Superclass org.apache.jsp.HttpJspBase of class org.apache.jsp.javabeantest$jsp not found.
public class javabeantest$jsp extends HttpJspBase {
^
2 errors, 1 warning
回复
skyboy0720 2004-08-26
抱的什么错误??
回复
haoming0 2004-08-26
<%@ page language="java" import="java.sql.*" %>
没有把自己的包,包含进来!!
<%@ page language="java" import="java.sql.*;Mysqltest.*" %>
应该就行了!你试试!!
回复
发动态
发帖子
Web 开发
创建于2007-09-28

7.9w+

社区成员

Java Web 开发
申请成为版主
社区公告
暂无公告