日期:2014-05-18  浏览次数:20619 次

JSP连接数据库的问题,请高手指点下!!
我想把数据循环存入数据库,但是只是存进一行数据,然后后面的就抛出异常。

<%@   page   contentType= "text/html;charset=GB2312 "   %>
<%@   page   import= "java.sql.* "   %>
<%!
public   String   codeToString(String   str)
{//处理中文字符串的函数
    String   s=str;
    try
        {
        byte   tempB[]=s.getBytes( "ISO-8859-1 ");
        s=new   String(tempB);
        return   s;
      }
    catch(Exception   e)
      {
        return   s;
      }    
}
%>
<%
for(int   i=1;i <=4;i++){
//接收客户端提交的数据
  String   list_number=codeToString(request.getParameter( "list_number "));
  int   id=i;
  String   sort_number=codeToString(request.getParameter( "sort_number_ "+i+ " "));
  if(sort_number==null)//无内容则设为空串
        sort_number= " ";
  String   e_name=codeToString(request.getParameter( "e_name_ "+i+ " "));
  if(e_name==null)//无内容则设为空串
        e_name= " ";
  String   e_size=codeToString(request.getParameter( "e_size_ "+i+ " "));
  if(e_size==null)//无内容则设为空串
        e_size= " ";
  String   unit=codeToString(request.getParameter( "unit_ "+i+ " "));
  if(unit==null)//无内容则设为空串
        unit= " ";
    String   amount=codeToString(request.getParameter( "amount_ "+i+ " "));
  if(amount==null)//无内容则设为空串
        amount= " ";
  String   location=codeToString(request.getParameter( "location_ "+i+ " "));
  if(location==null)//无内容则设为空串
        location= " ";
  String   facturer=codeToString(request.getParameter( "facturer_ "+i+ " "));
  if(facturer==null)//无内容则设为空串
        facturer= " ";
  String   s_date=codeToString(request.getParameter( "data "));
  if(s_date==null)//无内容则设为空串
        s_date= " ";
    //out.print(e_size);
  //构造追加记录SQL语句
 
String   sqlString= "insert   into   shouTable(list_number,id,sort_number,e_name,e_size,unit,amount,location,facturer,s_date) "+
                        "   values( ' "+list_number+ " ', ' "+id+ " ', ' "+sort_number+ " ', ' "+e_name+ " ', ' "+e_size+ " ', ' "+unit+ " ', ' "+amount+ " ', ' "+location+ " ', ' "+facturer+ " ', ' "+s_date+ " ') ";
  //执行SQL语句
try  
        {   Connection   con;
            Statement   sql;
            Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ");
          &nbs