这段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>
****************************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>
解决方案 »
- 求助
- 谁能帮我调试一下这个代码
- Java中的那些控件如何才能更好的控制啊?(比如说,JLabel,JButton, 文体框等啊)急啊!
- 『提问』java中怎样监视某个文件变化?
- 就剩一分了,看那个大侠能得到
- 如何得到下载文件的长度呀?http://86516.onlinedown.net/down/FlashFXP_3.3.8.1133_RC2_SC.exe
- 请问我安装JBuilder9后,Tomcat是否已安装,为什么http://localhost:8080没有欢迎界面
- 高分在线等待——关于JBuilder(或者使JVM)的使用问题?
- java数据导入导出的问题?
- GridBag Layout里的GridBagConstraint的weightx,weighty的取值问题?
- java中url.openstream()对于https的网页有用吗
- 返回什么结果?
name==null处理的不太对吧。当name为空,应该让输出全部或返回提示输入name。
exception org.apache.jasper.JasperException: Unable to compile class for JSPAn error occurred at line: 5 in the jsp file: /test4_1.jsp
Generated servlet error:
Syntax error, insert ";" to complete LocalVariableDeclarationStatement
哪里错了啊?请你指教一下...
少分号
少分号
************************************
谢谢 believefym(暮色,miss,迷失,miss)
是我太粗心了,忘了加分号....
______________________
问题解决了,谢谢大家..
String condition="SELECT * FROM stu_score WHERE 姓名 ="+"'"+name+"'"
应改为
String condition="SELECT * FROM stu_score WHERE 姓名 ='"+name+"'";
String condition="SELECT * FROM stu_score WHERE 姓名 ="+"'"+name+"'"
应改为
String condition="SELECT * FROM stu_score WHERE 姓名 ='"+name+"'";
"+"这个不用加