<%@ 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;
  }
}
%>
<% long userId=Long.parseLong(request.getParameter("userId")); 
%>
<%
 String username=codeToString(request.getParameter("username"));
 if(username==null)
    username=""; 
 String userRealName=codeToString(request.getParameter("userRealName"));
 if(userRealName==null)
    userRealName="";
 String userQq=codeToString(request.getParameter("userQq"));  
 int  userQqInt;
 try
 {
   userQqInt=Integer.parseInt(userQq.trim());
 }catch(Exception e)
 {
   userQqInt=0;
 }  
%><%
  String sqlString=null;
  sqlString="update userTable set username='"+username+"', userRealName='"+userRealName+"',userQq='"+userQqInt+
  "' where userId="+userId; 
 %>
 
 <% 
   //执行SQL语句
   try
   { 
     Connection con;
     Statement sql;
     Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
     con=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=userTable","sa","sa");
     sql=con.createStatement();
     sql.executeUpdate(sqlString);
     con.close();
   }catch(SQLException e1)
   {
    out.print("SQL异常!");
   }
 %><html>
<head>
<title>修改用户资料界面</title>
</head>
<body>
<center>
<table border="1" width="700">
  <tr>
    <td width="100%" colspan="2" align="center">修改普通用户资料</td>
  </tr>
  <tr>
    <td width="100%" colspan="2">修改用户资料成功!</td>
  </tr>
  </table>
</center>
</body>
</html>

解决方案 »

  1.   


    有,这是我写的一个更新信息的代码,运行后更新不了,显示是SQL异常,请指教,必结账!!!
      

  2.   

    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;
      }
    }这个方法有潜在问题。getBytes()调用前需要判断s != null
      

  3.   

    com.microsoft.jdbc.sqlserver.SQLServerDriver
     是不是写错了?
    com.microsoft.sqlserver.jdbc.SQLServerDriver
    这样的吧?