日期:2014-05-18  浏览次数:20684 次

JSP中用连接数据库
这是Java文件:
package   com.auto.evl;


import   java.sql.*;

/**
  *  
  *   @author   lpeter   SQLServer   连接测试
  *  
  */

public   class   DBConn   {

//   驱动类

static   String   driverClass   =

"com.microsoft.jdbc.sqlserver.SQLServerDriver ";

//   连接字符串

static   String   url   =

"jdbc:microsoft:sqlserver://127.0.0.1:1433;dataBaseName=RestaurantMIS_ShiLiHongZhuang ";

//   密码

static   String   password   =   " ";

//   用户名

static   String   username   =   "sa ";

//   待执行的   SQL   语句

static   String   sql   =   "SELECT   *   FROM   CY_CanTaiBiao ";
Connection   conn   =   null;
Statement   stmt   =   null;
ResultSet   rs   =   null;
        public     DBConn()   {
try   {
Class.forName(driverClass);
try   {
conn   =   DriverManager.getConnection(url,   username,   password);
}   catch   (SQLException   e)   {
e.printStackTrace();
}
}   catch   (ClassNotFoundException   e1)   {
e1.printStackTrace();
}

if   (conn   ==   null)   {//   连接没有关闭时关闭连接
                        System.out.print( "数据库连接错误 ");
}
        }
        public   Connection   getConnection()   {
        return   this.conn;
        }
}
这是JSP文件内容:
<%@   page   import= "java.sql.* "%>
<jsp:useBean   id= "Test "   class= "com.auto.evl.DBConn "   scope= "page "/>
<html>
<Body>
<%Test   T   =   new   Test();%>
</body>

</html>
这是错误信息:

An   error   occurred   at   line:   2   in   the   jsp   file:   /src/Login.jsp
Generated   servlet   error:
D:\jboss-3.2.8.SP1\jboss-3.2.8.SP1\jboss-3.2.8.SP1\server\default\work\jboss.web\localhost\Project\org\apache\jsp\src\Login_jsp.java:45:   package   com.auto.evl   does   not   exist
            com.auto.evl.DBConn   Test   =   null;


------解决方案--------------------

------解决方案--------------------
package com.auto.evl does not exist


=========包不存在
------解决方案--------------------
无法找到这个包 com.auto.evl does not exist