请教大家一个问题.........

liucom 2005-10-14 04:30:01
这段JSP代码不能运行,请问这是什么原因,环境设置没有问题,能连接数据库并能输出排序.但是在主页查询成绩时输入名字提交后就出错,不能正确输出...
****************************byname.jsp**************************************
<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import="java.sql.*" %>
<html>
<body>
<%
//获取提交的姓名
String name=request.getParameter("name");
if(name==null)
{
name=" ";

}
byte b[]=name.getBytes("ISO-8859-1");
name=new String(b);
Connection con=null;
Statement sql=null;
ResultSet rs=null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e) {}
try{
con=DriverManager.getConnection("jdbc:odbc:liu","sa","******");
sql=con.createStatement();
String condition="SELECT * FROM stu_score WHERE 姓名 ="+"'"+name+"'"
rs=sql.executeQuery(condition);
out.print("<Table Border>");
out.print("<TR>");
out.print("<TH width=100>"+"学号");
out.print("<TH width=100>"+"姓名");
out.print("<TH width=50>"+"数学成绩");
out.print("<TH width=50>"+"英语成绩");
out.print("<TH width=50>"+"物理成绩");
out.print("</TR>");
while(rs.next())
{
out.print("<TR>");
out.print("<TD>"+rs.getString(1)+"</TD>");
out.print("<TD>"+rs.getString(2)+"</TD>");
out.print("<TD>"+rs.getInt("数学成绩")+"</TD>");
out.print("<TD>"+rs.getInt("英语成绩")+"</TD>");
out.print("<TD>"+rs.getInt("物理成绩")+"</TD>");
out.print("</TR>");

}
out.print("</Table>");
con.close();
}
catch(SQLException e) { }
%>
</body>
</html>
...全文
107 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhengtu 2005-10-14
  • 打赏
  • 举报
回复
你的这条语句写错了
String condition="SELECT * FROM stu_score WHERE 姓名 ="+"'"+name+"'"
应改为
String condition="SELECT * FROM stu_score WHERE 姓名 ='"+name+"'";
"+"这个不用加
zhengtu 2005-10-14
  • 打赏
  • 举报
回复
你的这条语句写错了
String condition="SELECT * FROM stu_score WHERE 姓名 ="+"'"+name+"'"
应改为
String condition="SELECT * FROM stu_score WHERE 姓名 ='"+name+"'";
liucom 2005-10-14
  • 打赏
  • 举报
回复
String condition="SELECT * FROM stu_score WHERE 姓名 ="+"'"+name+"'"
少分号
************************************
谢谢 believefym(暮色,miss,迷失,miss。。。)
是我太粗心了,忘了加分号....
______________________
问题解决了,谢谢大家..
believefym 2005-10-14
  • 打赏
  • 举报
回复
String condition="SELECT * FROM stu_score WHERE 姓名 ="+"'"+name+"'"
少分号
wylsx 2005-10-14
  • 打赏
  • 举报
回复
学习
liucom 2005-10-14
  • 打赏
  • 举报
回复
soso119(soso119):
哪里错了啊?请你指教一下...
soso119 2005-10-14
  • 打赏
  • 举报
回复
jsp语法错了
liucom 2005-10-14
  • 打赏
  • 举报
回复
test4_1.jsp 就是上面的byname.jsp,我把test4_1.jsp改成了byname.jsp.
superslash 2005-10-14
  • 打赏
  • 举报
回复
test4_1.jsp贴出来看,好象局域变量声明是少了";"
liucom 2005-10-14
  • 打赏
  • 举报
回复
************************************byname.jsp**********************************
exception

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 5 in the jsp file: /test4_1.jsp
Generated servlet error:
Syntax error, insert ";" to complete LocalVariableDeclarationStatement
thumb3344 2005-10-14
  • 打赏
  • 举报
回复
建议:rs,sql,con都应该放在finally里面关闭
thumb3344 2005-10-14
  • 打赏
  • 举报
回复
报什么错?


name==null处理的不太对吧。当name为空,应该让输出全部或返回提示输入name。

62,629

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧