我把.jsp错误提示写出来,希望哪位大虾指教一下~~~~~~~~~~~~``:

alan520cf 2004-05-04 01:24:26
我把错误提示写出来,希望哪位大虾指教一下~~~~~~~~~~~~``:
源程序:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*"%>
<html>
<head>
<title>add message into table</title>
</head>
<body>
<%
String name=request.getParameter("name");
String mail=request.getParameter("mail");
String title=request.getParameter("title");
String content=request.getParameter("content");
if(name==null)
name="";
if(title==null)
title="";
if(content==null)
content="";
if(mail==null)
mail="";
if(name.length()==0)
out.println("留言人姓名不能为空!");
else
if(title.length()==0)
out.println("留言主题不能为空!");
else
if(content.length()==0)
out.println("留言内容不能为空!");
else
{
java.util.Date date=new java.util.Date();
String datetime=new Timestamp(date.getTime()).toString();
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//String url="jdbc:odbc:ClassDB";
Connection con=DriverManager.getConnection("jdbc:odbc:ClassDB","sa","sa");
java.sql.Statement stm=con.createStatement();
String querystr="insert into message(title,name,mail,time,content) values('";
querystr=querystr+title+"','"+name+"','"+mail+"','"+datetime+"','"+content+"')";

stm=con.prepareStatement("insert into message values(?,?,?,?,?)");
stm.setString(1,title);
stm.setString(2,name);
if(mail.length()==0)
stm.setString(3,null);
else
stm.setString(3,mail);
stm.setString(4,datetime);
stm.setString(5,content);
try
{
stm.excuteQuery();
}
catch(Exception e)
{}
con.close();
}
catch(Exception e)
{}
%>

<jsp:forward page="view_message.jsp"/>
<%
}
%>
</body>
</html>
---------------------------------------------------------------
运行时WEB页面提示错误:如下


/add_message.jsp:42: cannot resolve symbol
symbol : method setString (int,java.lang.String)
location: interface java.sql.Statement
stm.setString(1,title);
^
/add_message.jsp:43: cannot resolve symbol
symbol : method setString (int,java.lang.String)
location: interface java.sql.Statement
stm.setString(2,name);
^
/add_message.jsp:45: cannot resolve symbol
symbol : method setString (int,<nulltype>)
location: interface java.sql.Statement
stm.setString(3,null);
^
/add_message.jsp:47: cannot resolve symbol
symbol : method setString (int,java.lang.String)
location: interface java.sql.Statement
stm.setString(3,mail);
^
/add_message.jsp:48: cannot resolve symbol
symbol : method setString (int,java.lang.String)
location: interface java.sql.Statement
stm.setString(4,datetime);
^
/add_message.jsp:49: cannot resolve symbol
symbol : method setString (int,java.lang.String)
location: interface java.sql.Statement
stm.setString(5,content);
^
/add_message.jsp:52: cannot resolve symbol
symbol : method excuteQuery ()
location: interface java.sql.Statement
stm.excuteQuery();
^
...全文
11 8 点赞 打赏 收藏 举报
写回复
8 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
jarryhu 2004-05-05
超人一般了
你那就是低级错误了
PreparedStatement stm=con.PreparedStatement("insert into message values(?,?,?,?,?)");
该成:PreparedStatement stm=con.prepareStatement("insert into message values(?,?,?,?,?)");

  • 打赏
  • 举报
回复
away5678 2004-05-05
原代码呢.....
  • 打赏
  • 举报
回复
alan520cf 2004-05-04
嘿嘿~~~~~~~~~~``
晓的拉
谢谢拉~~~~~~~~~~~~~~~~~~~~~~~~
现在没有语法错误了,却反而有了语义错误
请大家帮我看一下错误提示,帮我指出错误所在啊
java.lang.IllegalArgumentException: Request cannot be null
at javax.servlet.ServletRequestWrapper.<init>(ServletRequestWrapper.java:95)
at javax.servlet.http.HttpServletRequestWrapper.<init>(HttpServletRequestWrapper.java:87)
at com.caucho.server.connection.RequestAdapter.<init>(RequestAdapter.java:96)
at com.caucho.server.webapp.DispatchRequest.<init>(DispatchRequest.java:97)
at com.caucho.server.webapp.DispatchRequest.createDispatch(DispatchRequest.java:107)
at com.caucho.server.webapp.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:164)
at com.caucho.server.webapp.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:112)
at com.caucho.jsp.PageContextImpl.forward(PageContextImpl.java:891)
at _jsp._add_0message__jsp._jspService(/add_message.jsp:84)
at com.caucho.jsp.JavaPage.service(JavaPage.java:75)
at com.caucho.jsp.Page.pageservice(Page.java:571)
at com.caucho.server.dispatch.PageFilterChain.doFilter(PageFilterChain.java:155)
at com.caucho.server.cache.CacheFilterChain.doFilter(CacheFilterChain.java:211)
at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:177)
at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:221)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:263)
at com.caucho.server.port.TcpConnection.run(TcpConnection.java:323)
at com.caucho.util.ThreadPool.runTasks(ThreadPool.java:430)
at com.caucho.util.ThreadPool.run(ThreadPool.java:377)
at java.lang.Thread.run(Thread.java:536)
  • 打赏
  • 举报
回复
alan520cf 2004-05-04
PreparedStatement stm=con.createStatement();
我改 成了这种定义,错误有减少
错误提示如下:
/add_message.jsp:39: incompatible types
found : java.sql.Statement
required: java.sql.PreparedStatement
PreparedStatement stm=con.createStatement();
^
/add_message.jsp:43: cannot resolve symbol
symbol : method PreparedStatement (java.lang.String)
location: interface java.sql.Connection
stm=con.PreparedStatement("insert into message values(?,?,?,?,?)");
^
/add_message.jsp:54: cannot resolve symbol
symbol : method excuteQuery ()
location: interface java.sql.PreparedStatement
stm.excuteQuery();
^
3 errors

前后矛盾的感觉
不知道哪位大虾 多指点一下~~~~~~~~~~~~~~```
  • 打赏
  • 举报
回复
alan520cf 2004-05-04
java.sql.Statement stm=con.createStatement();
PreparedStatement stm=con.createStatement();
两种方法我都试过了
都是错的
所以才问大家
希望各位大虾能再次看到这个萜子
你们的建议不管好与坏我都会去尝试
拜托了~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • 打赏
  • 举报
回复
away5678 2004-05-04
PreparedStatement stm=con.createStatement();

这个一看就知错了...
应该这样
PreparedStatement stm=con.PreparedStatement("insert into message values(?,?,?,?,?)");


  • 打赏
  • 举报
回复
away5678 2004-05-04
楼上的...
是应该从1开始的

楼主问题:
stm一开始定义为Statement(父类)后来用它来接收con.prepareStatement()
con.prepareStatement()是返回PreparedStatement(子类)
所以出错了...
原因是子类可以构造父类,而父类不可构造子类
通俗的说:
子类有的东西父类没有,父类有的东西子类都有
  • 打赏
  • 举报
回复
挑大梁 2004-05-04
stm.setString(1,title);
应从stm.setString(0,title);开始
  • 打赏
  • 举报
回复
相关推荐
发帖
Web 开发
加入

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2004-05-04 01:24
社区公告
暂无公告