首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

错哪了?新手,等待中,想了半天了

2013-09-11 
哪里错了?新手,等待中,想了半天了importjava.sql.Connectionimportjava.sql.DriverManagerimportjava.sq

哪里错了?新手,等待中,想了半天了
import   java.sql.Connection;
import   java.sql.DriverManager;
import   java.sql.ResultSet;
import   java.sql.SQLException;
import   java.sql.Statement;
import   java.util.Properties;

import   javax.naming.Context;
import   javax.naming.InitialContext;
import   javax.sql.DataSource;

//import   org.apache.commons.dbcp.BasicDataSource;

/**
  *  
  */
public   class   DataBase   {
private   static   DataSource   dts   =   null;

public   static   Connection   getConnection()   {
Connection   conn   =   null;
try   {
if   (dts   ==   null)   {
Class.forName(   "oracle.jdbc.driver.OracleDriver "   );  
String   url   =   "jdbc:oracle:thin:@************* ";  
conn   =   DriverManager.getConnection(url, "test ",   "test ");  
}
//conn   =   dts.getConnection();
}   catch   (Exception   e)   {
e.printStackTrace();
}

return   conn;
}

public   static   void   closeConnection(Connection   con,   Statement   stmt,
ResultSet   rs)   {
try   {
if   (rs   !=   null)   {
rs.close();
rs   =   null;
}
if   (stmt   !=   null)   {
stmt.close();
stmt   =   null;
}
if   (con   !=   null)   {
con.close();
con   =   null;
}

}   catch   (Exception   e)   {
e.printStackTrace();
}   finally   {
rs   =   null;
stmt   =   null;
con   =   null;
}
}
}
上面是写的DataBase,下面是JSP
<%@page   contentType= "text/html;charset=GBK "   import= "java.sql.* "%>
<html>
<title> 用户数据 </title>
<body>
<%        

Connection   conn=null;
Statement   stmt=null;
ResultSet   rs=null;

try{  

conn   =   DataBase.getConnection();
String   query= "select   *from   EMP ";
rs=stmt.executeQuery(query);
%>
<h4> 取出信息 </h4>
<table   border= "1 ">
<tr>
<th> TEMPO </th> <th> ENAME </th> <th> JOB </th> <th> MGR </th> <th> HIREDATE </th> <th> SAL </th> <th> COMM </th> <th> DEPTNO </th>
</tr>
<%
while(rs.next()){
out.println( " <tr> ");
out.println( " <td> "+rs.getString( "TEMPO ")+ " </td> ");
out.println( " <td> "+rs.getString( "ENAME ")+ " </td> ");
out.println( " <td> "+rs.getString( "JOB ")+ " </td> ");
out.println( " <td> "+rs.getString( "MGR ")+ " </td> ");
out.println( " <td> "+rs.getString( "HIREDATE ")+ " </td> ");
out.println( " <td> "+rs.getString( "SAL ")+ " </td> ");
out.println( " <td> "+rs.getString( "COMM ")+ " </td> ");


out.println( " <td> "+rs.getString( "DEPTNO ")+ " </td> ");
out.println( " </tr> ");
}
}catch(Exception   e){
e.printStackTrace();
}finally{
try{
DataBase.closeConnection(conn,stmt,rs);

}catch(Exception   e){
e.printStackTrace();
}
}
%>
</body>
</html>
运行了之后报错为:
type   Exception   report

message  

description   The   server   encountered   an   internal   error   ()   that   prevented   it   from   fulfilling   this   request.

exception  

org.apache.jasper.JasperException:   Unable   to   compile   class   for   JSP

An   error   occurred   at   line:   5   in   the   jsp   file:   /doJDBC.jsp
Generated   servlet   error:
E:\Eclipse\C\src\org\apache\jsp\doJDBC_jsp.java:55:   cannot   resolve   symbol
symbol     :   variable   DataBase  
location:   class   org.apache.jsp.doJDBC_jsp
conn   =   DataBase.getConnection();
                              ^


An   error   occurred   at   line:   22   in   the   jsp   file:   /doJDBC.jsp
Generated   servlet   error:
E:\Eclipse\C\src\org\apache\jsp\doJDBC_jsp.java:83:   cannot   resolve   symbol
symbol     :   variable   DataBase  
location:   class   org.apache.jsp.doJDBC_jsp
DataBase.closeConnection(conn,stmt,rs);
                                ^
2   errors


org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:332)
org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:412)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:472)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

这个问题怎么解决啊?
焦急等待中..................


[解决办法]
<%@page contentType= "text/html;charset=GBK " import= "java.sql.* "%>

还应该import你的DataBase类所在的包
[解决办法]
jsp 里的DataBase好象没定义吧 把DataBase类包进来就好了
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html
我的异常网推荐解决方案:org.apache.jasper.JasperException: Unable to compile class,http://www.myexception.cn/j2ee/2308.html

热点排行