|
Java学习者论坛
本人新手,我想用一个javabean把jsp和mysql连接起来,然后在dreamweaver下做了一个测试文件来测试javabean是否能用.但是在dreamweaver按下f12之后在tomcat的日志文件里面出现了以下错误代码.请教一下这是怎么回事,如何解决.感谢感谢!!!
开发环境tomcat7.0.19 dreamweaver8 myeclipse9.0 mysql5.18
八月 09, 2011 4:09:52 下午 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet [jsp] in context with path [/test] threw exception [javax.servlet.ServletException: java.lang.NoSuchMethodError: test.db.DatabaseCon.getString(Ljava/sql/ResultSet;Ljava/lang/String;)Ljava/lang/String;] with root cause
java.lang.NoSuchMethodError: test.db.DatabaseCon.getString(Ljava/sql/ResultSet;Ljava/lang/String;)Ljava/lang/String;
at org.apache.jsp.testBean_jsp._jspService(testBean_jsp.java:85)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:433)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(Applicatio2nFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:851)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:257)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1764)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
javabean如下:
package test.db;
import java.io.*;
import java.sql.*;
public class DatabaseCon {
public Connection con;
public String dbDriver="org.gjt.mm.mysql.Driver";
public String URL = "jdbc:mysql://localhost:3306/tcpl";
public String Message;
public Statement stmt=null;
public boolean connection() {
try{
Class.forName("dbDriver");
}
catch(ClassNotFoundException ex){
Message=ex.getMessage();
System.exit(-1);
}
try{
con = DriverManager.getConnection(URL,"root","1");
return true;
}
catch(SQLException ex){
Message=ex.getMessage();
return false;
}
}
public ResultSet exeSQL( String sqlstr) {
try{
con = DriverManager.getConnection(URL,"root","1");
stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(sqlstr);
return rs;
} catch(Exception ex){
Message=ex.getMessage();
}
return null;
}
public String getString(ResultSet rs,String str){
try{
return rs.getString(str);
}catch(Exception ex){
Message=ex.getMessage();
}
return null;
}
public boolean close(){
try{
con.close();
return true;
}
catch(Exception ex){
Message=ex.getMessage();
return false;
}
}
}
测试文件如下:
<%@ page contentType="text/HTML; charset=GB2312" import="java.sql.*" %>
<html>
<head>
<title>
测试数据库连接Bean
</title>
</head>
<jsp:useBean id="dbBean" scope="session" class="test.db.DatabaseCon" />
<body bgcolor="#ffffff">
<%
ResultSet rs=dbBean.exeSQL("select * from tushumingxi");
String str;
try{
while(rs.next()){
str=dbBean.getString(rs,"banshe");%>
【<%=dbBean.getString(rs,"shu_name")%>】 -> <%=str%><br>
<%
}}catch(Exception ex){
out.print(ex.getMessage());
}
%>
</body>
</html>
Java学习者论坛欢迎来到Java学习者论坛,转载请注明地址:http://www.javaxxz.com. |
|