jsp 访问数据库问题:出现 conn cannot be resolved
数据库连接文件:datalin.jsp<%@pagecontentType="text/html;charset=GB2312"language="java"import...
数据库连接文件:datalin.jsp
<%@ page contentType="text/html; charset=GB2312" language="java" import="java.sql.*" errorPage="" %>
<%
.....代码省略..........
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
Connection conn =null;
conn=DriverManager.getConnection(url);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
%>
---------------------------------
取得数据文件:getdata.jsp
<%@ page contentType="text/html; charset=GB2312" language="java" import="java.sql.*" errorPage="" %>
<%@ page language="java"%>
<%@ include file="dataline.jsp"%>
.....代码省略..........
<%!
String getArealnfo(String postalCode){
String arealnfo=null;
String sql="select * from postalcode where code like ?";
try{
ResultSet rss=null;
PreparedStatement pstmt=conn.prepareStatement(sql);
// PreparedStatement pstmt=conn.prepareStatement(sql);
pstmt.setString(1,postalCode);
rss=pstmt.executeQuery();
if(rss.next())
{
arealnfo=rss.getString("area")+"|"+rss.getString("city");
}else{
rss.close();
pstmt.setString(1,postalCode.substring(0,4)+"00");
rss=pstmt.executeQuery();
if(rss.next())
{
arealnfo=rss.getString("area")+"|"+rss.getString("city");
}
}
}catch(SQLException e){
System.out.println(e.toString());
}finally{
}
return arealnfo;
}
%>
出现问题:
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 25 in the jsp file: /getdata.jsp
conn cannot be resolved
22:
23: try{
24: ResultSet rss=null;
25: PreparedStatement pstmt=conn.prepareStatement(sql);
26: // PreparedStatement pstmt=conn.prepareStatement(sql);
27: pstmt.setString(1,postalCode);
28: rss=pstmt.executeQuery();
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:423)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:317)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:282)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:586)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.18 logs.
老是出现 conn cannot be resolved 为什么???怎么处理? 展开
<%@ page contentType="text/html; charset=GB2312" language="java" import="java.sql.*" errorPage="" %>
<%
.....代码省略..........
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
Connection conn =null;
conn=DriverManager.getConnection(url);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
%>
---------------------------------
取得数据文件:getdata.jsp
<%@ page contentType="text/html; charset=GB2312" language="java" import="java.sql.*" errorPage="" %>
<%@ page language="java"%>
<%@ include file="dataline.jsp"%>
.....代码省略..........
<%!
String getArealnfo(String postalCode){
String arealnfo=null;
String sql="select * from postalcode where code like ?";
try{
ResultSet rss=null;
PreparedStatement pstmt=conn.prepareStatement(sql);
// PreparedStatement pstmt=conn.prepareStatement(sql);
pstmt.setString(1,postalCode);
rss=pstmt.executeQuery();
if(rss.next())
{
arealnfo=rss.getString("area")+"|"+rss.getString("city");
}else{
rss.close();
pstmt.setString(1,postalCode.substring(0,4)+"00");
rss=pstmt.executeQuery();
if(rss.next())
{
arealnfo=rss.getString("area")+"|"+rss.getString("city");
}
}
}catch(SQLException e){
System.out.println(e.toString());
}finally{
}
return arealnfo;
}
%>
出现问题:
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 25 in the jsp file: /getdata.jsp
conn cannot be resolved
22:
23: try{
24: ResultSet rss=null;
25: PreparedStatement pstmt=conn.prepareStatement(sql);
26: // PreparedStatement pstmt=conn.prepareStatement(sql);
27: pstmt.setString(1,postalCode);
28: rss=pstmt.executeQuery();
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:423)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:317)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:282)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:586)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.18 logs.
老是出现 conn cannot be resolved 为什么???怎么处理? 展开
4个回答
展开全部
从这个信息可以看出在编译的时候没有找到此类的包,所以在你的JSP页面中只要导入Conn类的包就能解决这个问题
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这个错误,一般都是语法错误,你仔细看看。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
楼主同志,我看了半天没找到你的连接字符串,检查一下连接字符串吧,这地方最容易出问题。asp很久不用了,忘差不多了。。。不过数据库一般就是连接字符串出问题
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |