为什么?
<html>
<body>
<%session.setAttribute( "username ",session.getAttribute( "username "));%>
<form method= "post " action= "booksend.jsp ">
<table width= "638 " height= "314 " border= "0 " align= "center " cellpadding= "0 " cellspacing= "0 ">
<!--DWLayoutTable-->
<tr>
<td width= "612 " height= "159 " valign= "top " background= "images/show.gif " class= "word "> <p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<blockquote>
<p align= "left "> 1�� ������ı����ͼ��������һ�ࣿ </p>
<p align= "left ">
<input name= "type " type= "checkbox " value= "kaifa " >
�����ֲ�
<input name= "type " type= "checkbox " value= "baili ">
����
<input name= "type " type= "checkbox " value= "jiqiao ">
����
<input name= "type " type= "checkbox " value= "shili ">
ʵ���
<input name= "type " type= "checkbox " value= "jiaocheng ">
�̳� </p>
<p align= "left "> 2�� ��ʹ���������ֱ�����Ի򹤾�? </p>
<p align= "left ">
<input name= "type2 " type= "checkbox " value= "VB " >
VB
<input name= "type2 " type= "checkbox " value= "VC ">
VC++
<input name= "type2 " type= "checkbox " value= "JAVA ">
JAVA
<input name= "type2 " type= "checkbox " value= "DELPHI ">
DELPHI
<input name= "type2 " type= "checkbox " value= "ASP ">
ASP
<input name= "type2 " type= "checkbox " value= "ASPNET ">
ASP.NET
<input name= "type2 " type= "checkbox " value= "JSP ">
JSP
<input name= "type2 " type= "checkbox " value= "OTHER ">
���� </p>
<p> 3�� ����Ը�⹺����������ͼ��? </p>
<p>
<input name= "type3 " type= "checkbox " value= "rumen " >
������ͼ��
<input name= "type3 " type= "checkbox " value= "jiangjie ">
����+ʵ��
<input name= "type3 " type= "checkbox " value= "wanquan ">
��ȫʵ��
<input name= "type3 " type= "checkbox " value= "baili ">
������
<input name= "type3 " type= "checkbox " value= "jiqiao ">
������ </p>
</blockquote>
<p align= "center ">
<input type= "submit " name= "aa " value= "�ύ ">
</p>
<p align= "left "> </p> </td>
</tr>
</table>
</body>
</html>
-------------------------------
<%@ page contentType= "text/html;charset=gb2312 " language= "java " import= "java.sql.*,java.io.* "%>
<%@ include file= "include.inc "%>
<%session.setAttribute( "username ",session.getAttribute( "username "));%>
<html>
<style type= "text/css ">
<!--
.style1 {font-size: 18px}
-->
</style>
<body>
<%
Class.forName(CLASSFORNAME);
Connection con=DriverManager.getConnection(SERVER,USER,PWD);
Statement stmt=con.createStatement();
String type[]=request.getParameterValues( "type ");
String type2[]=request.getParameterValues( "type2 ");
String type3[]=request.getParameterValues( "type3 ");
%>
<%
if(type!=null)
{
for(int i=0;i <type.length;i++)
{
String aa=type[i];
try
{
stmt.executeUpdate( "update tb_book set "+aa+ "= "+aa+ " + 1 where id=1 ");
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
if(type2!=null)
{
for(int i=0;i <type2.length;i++)
{
String aa=type2[i];
try
{
stmt.executeUpdate( "update tb_language set "+aa+ "= "+aa+ " + 1 where id=1 ");
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
if(type3!=null)
{
for(int i=0;i <type3.length;i++)
{
String aa=type3[i];
try
{
stmt.executeUpdate( "update tb_borrowbook set "+aa+ "= "+aa+ " + 1 where id=1 ");
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
%>
<%
ResultSet rs1=stmt.executeQuery( "select * from tb_book where id=1 ");
if(rs1.next())
{
%>
<center> <h2> 明日科技 图书市场调研卡 </h2>
<table width= "567 " height= "176 ">
<tr> <td> <h3> 调查结果: </h3> </tr> </td>
<tr> <td> <h4> 1、您经常购买的编程类图书属于哪一类? </h4> </td> </tr>
<tr> <td>
开发手册类得票: <%=rs1.getString( "kaifa ")%> 票 <br>
百例类得票: <%=rs1.getString( "baili ")%> 票 <br>
技巧类: <%=rs1.getString( "jiqiao ")%> 票 <br>
实例集锦类: <%=rs1.getString( "shili ")%> 票 <br>
教程类: <%=rs1.getString( "jiaocheng ")%> 票
</td> </tr>
<%
}
ResultSet rs2=stmt.executeQuery( "select * from tb_language where id=1 ");
if(rs2.next())
{
%>
<tr> <td> <h4> 2、您使用下面哪种编程语言或工具? </h4> </td> </tr>
<tr> <td>
VB得票: <%=rs2.getString( "VB ")%> 票 <br>
VC++得票: <%=rs2.getString( "VC ")%> 票 <br>
JAVA得票: <%=rs2.getString( "JAVA ")%> 票 <br>
DELPHI得票: <%=rs2.getString( "DELPHI ")%> 票 <br>
ASP得票: <%=rs2.getString( "ASP ")%> 票 <br>
ASP.NET得票: <%=rs2.getString( "ASPNET ")%> 票 <br>
JSP得票: <%=rs2.getString( "JSP ")%> 票 <br>
其他得票: <%=rs2.getString( "OTHER ")%> 票
</td> </tr>
<%
}
ResultSet rs3=stmt.executeQuery( "select * from tb_borrowbook where id=1 ");
if(rs3.next())
{
%>
<tr> <td> <h4> 3、您最愿意购买或借阅哪类图书? </h4> </td> </tr>
<tr> <td>
入门类图书得票: <%=rs3.getString( "rumen ")%> 票 <br>
讲解+实例类得票: <%=rs3.getString( "jiangjie ")%> 票 <br>
完全实例类得票: <%=rs3.getString( "wanquan ")%> 票 <br>
百例型类得票: <%=rs3.getString( "baili ")%> 票 <br>
技巧类得票: <%=rs3.getString( "jiqiao ")%> 票 <br>
</td> </tr>
<%}
%>
</table>
<p align= "center " class= "style1 "> <a href= "tuichu.jsp "> 退出 </a> </p>
</body>
</html>
------------------------------
为什么 写不进去!!!!!!!!!!!页面根本没反映 数据库保证能连上 但写不进去数据!
[解决办法]
"update tb_borrowbook set "+aa+ "= "+aa+ " + 1 where id=1 "
sql语句的语法有问题set后边应该是字段名,你那怎么是变量名,还是先在查询分析器试好了再往程序里放吧.
[解决办法]
stmt.executeUpdate( "update tb_borrowbook set "+aa+ "= "+aa+ " + 1 where id=1 ");
1.首先有楼上说的问题,但不全是,只要你确定字段名,使用变量名一样OK
如果以type为例,aa变量值为 "kaifa "时
stmt.executeUpdate( "update tb_borrowbook set "+aa+ "= "+aa+ " + 1 where id=1 ");
==
stmt.executeUpdate( "update tb_borrowbook set kaifa= kaifa + 1 where id=1 ");
其中kaifa + 1你作什么理解?
2.没用过这种方法,在我的印象中一个statement只有一次作用,另一种说法就是你中for循环多次调用同一个statement是没有用的,改正为batch方式,在for循环中添加batch,for循环完成后执行batch.
3.另外建议.别在for循环中写try...catch