我做一个添加新数据的jsp动态网页,错误信息提示“标准表达式中数据类型不匹配”这一问题怎么解决?
我做一向Access数据库添加新数据的jsp动态网页,我的处理数据添加的jsp网页代码如下:<%//加载驱动类Class.forName("sun.jdbc.odbc.J...
我做一向Access数据库添加新数据的jsp动态网页,我的处理数据添加的jsp网页代码如下:
<%
//加载驱动类
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//连接字符串
String url = "jdbc:odbc:NewsDatabase";
//连接用户名及密码,在Access里一般为空
String user = "";
String pwd = "";
//创建连接
Connection con = DriverManager.getConnection(url, user, pwd);
//建立Statement操作对象
Statement stmt = con.createStatement();
//建立ResultSet结果集,并执行SQL语句
request.setCharacterEncoding("gb2312");
String title=request.getParameter("txtTitle");
String write=request.getParameter("txtwrite");
String time=request.getParameter("txtuptime");
String content=request.getParameter("txtContent");
String typeid=request.getParameter("typeid");
String str="insert into newsinfo (title,content,typeId,writers,uptime) values ('"+title+"','"+content+"','"+typeid+"','"+write+"','"+time+"')";
int exeRsult = stmt.executeUpdate(str);
%>
<body>
<%
if(exeRsult>0) {
%>
<span class="STYLE7">你成功添加一篇文章!</span>
<%
}
else {
%>
<span class="STYLE7">你添加文章失败!</span>
<%
}
%>
主要的错误信息如下:
org.apache.jasper.JasperException: An exception occurred processing JSP page /doaddnews.jsp at line 49
46: String content=request.getParameter("txtContent");
47: String typeid=request.getParameter("typeid");
48: String str="insert into newsinfo (title,content,typeId,writers,uptime) values ('"+title+"','"+content+"','"+typeid+"','"+write+"','"+time+"')";
49: int exeRsult = stmt.executeUpdate(str);
50:
51:
52:
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:524)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:417)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
javax.servlet.ServletException: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] 标准表达式中数据类型不匹配。
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:850)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)
org.apache.jsp.doaddnews_jsp._jspService(doaddnews_jsp.java:147)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
我的Access数据库中newsId字段设为自动编号类型,content设为备注类型,uptime设为日期/时间类型,writes、typeId、title都为文本类型,请求各位朋友帮我解决这一问题,我在线等待,谢谢!
Access数据库有varchar类型吗?求教怎么改变量类型,能说详细点吗? 展开
<%
//加载驱动类
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//连接字符串
String url = "jdbc:odbc:NewsDatabase";
//连接用户名及密码,在Access里一般为空
String user = "";
String pwd = "";
//创建连接
Connection con = DriverManager.getConnection(url, user, pwd);
//建立Statement操作对象
Statement stmt = con.createStatement();
//建立ResultSet结果集,并执行SQL语句
request.setCharacterEncoding("gb2312");
String title=request.getParameter("txtTitle");
String write=request.getParameter("txtwrite");
String time=request.getParameter("txtuptime");
String content=request.getParameter("txtContent");
String typeid=request.getParameter("typeid");
String str="insert into newsinfo (title,content,typeId,writers,uptime) values ('"+title+"','"+content+"','"+typeid+"','"+write+"','"+time+"')";
int exeRsult = stmt.executeUpdate(str);
%>
<body>
<%
if(exeRsult>0) {
%>
<span class="STYLE7">你成功添加一篇文章!</span>
<%
}
else {
%>
<span class="STYLE7">你添加文章失败!</span>
<%
}
%>
主要的错误信息如下:
org.apache.jasper.JasperException: An exception occurred processing JSP page /doaddnews.jsp at line 49
46: String content=request.getParameter("txtContent");
47: String typeid=request.getParameter("typeid");
48: String str="insert into newsinfo (title,content,typeId,writers,uptime) values ('"+title+"','"+content+"','"+typeid+"','"+write+"','"+time+"')";
49: int exeRsult = stmt.executeUpdate(str);
50:
51:
52:
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:524)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:417)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
javax.servlet.ServletException: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] 标准表达式中数据类型不匹配。
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:850)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)
org.apache.jsp.doaddnews_jsp._jspService(doaddnews_jsp.java:147)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
我的Access数据库中newsId字段设为自动编号类型,content设为备注类型,uptime设为日期/时间类型,writes、typeId、title都为文本类型,请求各位朋友帮我解决这一问题,我在线等待,谢谢!
Access数据库有varchar类型吗?求教怎么改变量类型,能说详细点吗? 展开
4个回答
展开全部
数据库的数据类型不一致造成的!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你可以把sql拿出来在plsql试下.这样是检查问题最好的方法
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
类型吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询