在JSP 中使用JSTL 访问Access数据库
1 . 用控制面板 ODBC 数据原管理建立一个MS Access 驱动,DSN = example 关联到book.mdb 里面只有一个表 表名Employee 
2 . 在WEB-INF目录下修改web.xml 加入:
<web-app>
...
<context-param>
  <param-name>
    javax.servlet.jsp.jstl.sql.dataSource
  </param-name>
  <param-value>
    jdbc:odbc:example,sun.jdbc.odbc.JdbcOdbcDriver
  </param-value>
</context-param>
...
</web-app>3 在对应的JSP页面里使用:
<sql:query var="empDbInfo">
  SELECT * FROM Employee 
    WHERE UserName = ?
  <sql:param value="${param.userName}" />
</sql:query>
来访问数据库出错:
javax.servlet.ServletException: Unable to get connection, DataSource invalid: "General error"不解.. 不知道哪步错了 还是有地方没有设置?? 求大侠指教指教这是O'Reilly的 Java Server Page 2nd edit 中的ch11的一个例子 其中有一端是这样:The second part -- the JDBC driver class name -- must be specified as a fully qualified class name; in other words, the class name including the package name. You must install the driver by placing its class files in a place the web container can find, typically in the application's WEB-INF/lib directory. If the driver is delivered as a ZIP file (as Oracle's JDBC drivers are,for instance), you can still place it in the WEB-INF/lib directory if you change the file extension from .zip to.jar.
大概意思需要安装JDBC驱动到WEB 容器能识别的位置 典型如WEB-INF/lib 目录下.
不明白了 JDBC 驱动还要另外安装么?? JDBC 不是应该包含在了J2SDK 里了么??
不解.. 求高人指教

解决方案 »

  1.   

    错,JDK只提借了数据库操作的接口,具体的实现是各数据库厂商各自实现的,也就是JDBC驱动类如何实现各数据库厂商自己实现,你在通过JDBC访问某种类型的数据库之前,必须该数据库类型驱动包加载到CLASSPATH中,这样你才可以访问该数据库了
      

  2.   

    啊 原来如此..
    看来我对JDBC 太不了解才会有这样的问题..
    要多看看书了