将JSP数据插入MS Access数据库?

时间:2013-06-24 14:31:23

标签: html jsp ms-access

尝试将使用JSP从html页面检索的数据插入到MS Access数据库的表中时,我一直遇到不同的错误。每次我尝试修复或更改我的代码时都会遇到不同的错误。目前的错误是:

(ps。我正在使用apache tomcat。我的数据库名为“tico”,“Contacts”是表的名称.MS访问中的字段名称是“Job Code:”和“TICo的Client:”) 。如果有人可以提供帮助,我们将不胜感激。谢谢。 :)

-------------------------------------------------------------------------
enter code here 

HTTP Status 500 - An exception occurred processing JSP page /TICo Website/onejsp.jsp     at line 21

type Exception report

message An exception occurred processing JSP page /TICo Website/onejsp.jsp at line 21

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

exception

org.apache.jasper.JasperException: An exception occurred processing JSP page /TICo Website/onejsp.jsp at line 21

 18:      url = "jdbc:odbc:tico" 
 19: />
 20: 
 21: <sql:update var="tico" scope="request" dataSource ="${tico}">
 22:  INSERT INTO Contacts
 23:  ([Job Code:], [TICo's Client:])
 24:  VALUES (?, ?)

                                                                                            Stacktrace:  
                                                                                             org.apache.jasper.servlet.JspServletWrapper.handleJspException

(JspServletWrapper.java:521)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:412)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)        
 org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:723)

 root cause

 javax.servlet.ServletException: javax.servlet.jsp.JspException: Unable to get   
  connection, 
   DataSource invalid: "java.sql.SQLException: [Microsoft]
   [ODBC Driver Manager]           
    Data source name not found and no default driver specified"     
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException
   (PageContextImpl.java:865)

   org.apache.jasper.runtime.PageContextImpl.handlePageException
  (PageContextImpl.java:794)
   org.apache.jsp.TICo_0020Website.onejsp_jsp._jspService(onejsp_jsp.java:215)
   org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
   org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
   org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
   org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:723)

   root cause

   javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid:
   "java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name 
   not found and   no     default driver specified"
  org.apache.taglibs.standard.tag.common.sql.UpdateTagSupport.
  getConnection(UpdateTagSupport.   java:243)
 org.apache.taglibs.standard.tag.common.sql.UpdateTagSupport.doStartTag
 (UpdateTagSupport.jav     a:124)

 org.apache.jsp.TICo_0020Website.onejsp_jsp._jspx_meth_sql_005fupdate_005f0
 (onejsp_jsp.java:    264)

org.apache.jsp.TICo_0020Website.onejsp_jsp._jspService(onejsp_jsp.java:80)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:723)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)    

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:723)

note The full stack trace of the root cause is available in the Apache     
Tomcat/6.0.37     logs.
Apache Tomcat/6.0.37


----------------------------------------------------------------------------------
full stack trace
-------------------------------------------------------------------------------

enter code hereJun 25, 2013 9:54:33 AM   
org.apache.catalina.core.AprLifecycleListener    init 

INFO: The APR based Apache Tomcat Native library which allows optimal performance 

in production environments was not found on the java.library.path: C:\Program 
 Files\Apache    Software Foundation\Tomcat 6.0\bin;C:\Windows\Sun\Java\bin;C:

\Windows    \system32;C:\Windows;C:\Windows\system32;C:\Windows;C:\Windows\System32
 \Wbem;C:\Windows    \System32\WindowsPowerShell\v1.0\;;.    

Jun 25, 2013 9:54:33 AM org.apache.coyote.http11.Http11Protocol init

INFO: Initializing Coyote HTTP/1.1 on http-8080

Jun 25, 2013 9:54:33 AM org.apache.catalina.startup.Catalina load

INFO: Initialization processed in 438 ms

Jun 25, 2013 9:54:33 AM org.apache.catalina.core.StandardService start

INFO: Starting service Catalina

Jun 25, 2013 9:54:33 AM org.apache.catalina.core.StandardEngine start

INFO: Starting Servlet Engine: Apache Tomcat/6.0.37

Jun 25, 2013 9:54:33 AM org.apache.catalina.startup.HostConfig deployDescriptor

INFO: Deploying configuration descriptor manager.xml

Jun 25, 2013 9:54:33 AM org.apache.catalina.startup.HostConfig deployDirectory

INFO: Deploying web application directory docs

Jun 25, 2013 9:54:33 AM org.apache.catalina.startup.HostConfig deployDirectory

INFO: Deploying web application directory ROOT

Jun 25, 2013 9:54:34 AM org.apache.coyote.http11.Http11Protocol start

INFO: Starting Coyote HTTP/1.1 on http-8080

Jun 25, 2013 9:54:34 AM org.apache.jk.common.ChannelSocket init

INFO: JK: ajp13 listening on /0.0.0.0:8009

Jun 25, 2013 9:54:34 AM org.apache.jk.server.JkMain start

INFO: Jk running ID=0 time=0/15  config=null

Jun 25, 2013 9:54:34 AM org.apache.catalina.startup.Catalina start

 INFO: Server startup in 800 ms

Jun 25, 2013 10:03:14 AM org.apache.coyote.http11.Http11Protocol pause

INFO: Pausing Coyote HTTP/1.1 on http-8080

Jun 25, 2013 10:03:15 AM org.apache.catalina.core.StandardService stop

INFO: Stopping service Catalina

Jun 25, 2013 10:03:15 AM org.apache.coyote.http11.Http11Protocol destroy

INFO: Stopping Coyote HTTP/1.1 on http-8080

Jun 25, 2013 10:03:21 AM org.apache.catalina.core.AprLifecycleListener init   

INFO: The APR based Apache Tomcat Native library which allows optimal performance 

in production environments was not found on the java.library.path: C:\Program 

Files\Apache   Software Foundation\Tomcat 6.0\bin;C:\Windows\Sun\Java\bin;C:\Windows  

\system32;C:\Windows;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:
\Windows   \System32\WindowsPowerShell\v1.0\;;.   

Jun 25, 2013 10:03:21 AM org.apache.coyote.http11.Http11Protocol init

INFO: Initializing Coyote HTTP/1.1 on http-8080

Jun 25, 2013 10:03:21 AM org.apache.catalina.startup.Catalina load

INFO: Initialization processed in 348 ms

Jun 25, 2013 10:03:21 AM org.apache.catalina.core.StandardService start

INFO: Starting service Catalina

Jun 25, 2013 10:03:21 AM org.apache.catalina.core.StandardEngine start

INFO: Starting Servlet Engine: Apache Tomcat/6.0.37

Jun 25, 2013 10:03:21 AM org.apache.catalina.startup.HostConfig deployDescriptor

INFO: Deploying configuration descriptor manager.xml

Jun 25, 2013 10:03:21 AM org.apache.catalina.startup.HostConfig deployDirectory

INFO: Deploying web application directory docs

Jun 25, 2013 10:03:21 AM org.apache.catalina.startup.HostConfig deployDirectory

INFO: Deploying web application directory ROOT

Jun 25, 2013 10:03:22 AM org.apache.coyote.http11.Http11Protocol start

INFO: Starting Coyote HTTP/1.1 on http-8080

Jun 25, 2013 10:03:22 AM org.apache.jk.common.ChannelSocket init

INFO: JK: ajp13 listening on /0.0.0.0:8009

Jun 25, 2013 10:03:22 AM org.apache.jk.server.JkMain start

INFO: Jk running ID=0 time=0/15  config=null

Jun 25, 2013 10:03:22 AM org.apache.catalina.startup.Catalina start

INFO: Server startup in 495 ms`

JSP页面

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>  
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>

<html>
<head>
<title>Using GET and POST Method to Read Form Data</title>
</head>
<body>                  

<sql:setDataSource
    var = "tico" 
    scope = "session" 
    driver = "sun.jdbc.odbc.JdbcOdbcDriver"
    url = "jdbc:odbc:tico" 
 />

 <sql:update var="tico" scope="request" dataSource ="${tico}">
 INSERT INTO Contacts
 (Job Code:, TICo's Client:)
 VALUES (?, ?)
 <sql:param value = "${param.jobcode}" />
 <sql:param value = "${param.ticosclient}" />
 </sql:update>  

 <center>
 <h1>Using GET Method to Read Form Data</h1>
 <div style="position:absolute; top:20px; width:100%; height:80px;">
 <ul>
 <table align='center' style="width: 1000px; height: 81px;" border="0" cellpadding="0" 
  cellspacing="0" align="center">
  <col width="33">
  <col width="33">
   <col width="33">
   <col width="33"></br></br></br>

<tr><td>     
<li><p><b>Job Code:</b>
   <%= request.getParameter("jobcode")%>
</p></li>
</td></tr>

<tr><td>
<li><p><b>TICo's Client:</b>
   <%= request.getParameter("ticosclient")%>
</p></li>
</td></tr>

</body>
</html>

1 个答案:

答案 0 :(得分:0)

当然,您需要修复的一件事是您的SQL命令文本。

INSERT INTO Contacts
(Job Code:, TICo's Client:)
VALUES (?, ?)

必须更改为

INSERT INTO Contacts
([Job Code:], [TICo's Client:])
VALUES (?, ?)

顺便说一句,您可能需要仔细检查字段名称中是否确实存在冒号(:)字符。这对于表单上的标签来说非常正常,但它们包含在实际的字段名称中却相当不寻常。

修改

未找到&#34;数据源名称且未指定默认驱动程序&#34;错误表明JSP进程在64位环境中运行,并且服务器上尚未安装64位版本的Access数据库引擎(a.k.a。&#34; ACE&#34;)。要更正此问题,请从here下载并安装64位版本的Access数据库引擎,然后为数据库创建64位系统DSN(通过常规Windows控制面板小程序,而不是SYSWOW64)。 p>