环境JDK+TOMCAT
jsp代码:
 <%@ page contentType="text/html;charset=GB2312" %>
<%@ page import="java.sql.*" %>
<html>
<head>
<%
response.setCharacterEncoding("GBK");
String name=request.getParameter("name");
String pass=request.getParameter("password");
String telephone=request.getParameter("telephone");
String adress=request.getParameter("adress");
String birthday=request.getParameter("birthday");
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
}
catch(ClassNotFoundException e)
{
out.print("类找不到!");
}
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=myjob";
String user="sa";
String password="";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String  s="'"+name+"'"+"'"+"'"+pass+"'"+"'"+"'"+telephone+"'"+"'"+"'"+adress+"'"+"'"+"'"+birthday+"'";
String  verify="insert into user1  values "+"("+s+")";
ResultSet rs=stmt.executeQuery(verify);
if(rs.next()){    
response.sendRedirect("index.jsp");}
else{   
response.sendRedirect("zhuce.jsp");}  
rs.close();     
stmt.close();     
conn.close(); 
%>
</head><body>
</body>
</html>
当我运行页面的时候提示:
org.apache.jasper.JasperException: javax.servlet.ServletException: java.sql.SQLException: [Microsoft][SQLServer JDBC Driver][SQLServer]在关键字 'null' 附近有语法错误。
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:532)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:408)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause javax.servlet.ServletException: java.sql.SQLException: [Microsoft][SQLServer JDBC Driver][SQLServer]在关键字 'null' 附近有语法错误。
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:855)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:784)
org.apache.jsp.zhuce1_jsp._jspService(zhuce1_jsp.java:100)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:384)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)不知道为什么,请高手帮解决,谢谢!!

解决方案 »

  1.   

    你的SQL语句写错了.
    insert into user1 values ('name'''password'''telephone'''adress'''birthday') 
    这个是你写的.
    String  s="'"+name+"'"+","+"'"+pass+"'"+","+"'"+telephone+"'"+","+"'"+adress+"'"+","+"'"+birthday+"'";
      

  2.   

    还是提示报错
    org.apache.jasper.JasperException: An exception occurred processing JSP page /zhuce1.jsp at line 2623: Connection conn= DriverManager.getConnection(url,user,password);
    24: Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
    25: String  verify="insert into user1  values ('name'''password'''telephone'''adress'''birthday')";
    26: ResultSet rs=stmt.executeQuery(verify);
    27: if(rs.next()){    
    28: response.sendRedirect("index.jsp");}
    29: else{   
      

  3.   

    把26之后的语句放到TRY块里,在CATCH块里输出下异常的信息来看看.
    try{
    //你26行之后的代码}catch(Exception ex)
    {System.out.print(ex.getMessage());}还有,你第25行的代码好象还是有问题.
    在25 26行间加一句
    System.out.println(verify);
    看看打出来的是什么,把这句话贴到查询分析器里看看去.