首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

有关一个注册有关问题

2012-01-08 
有关一个注册问题环境JDK+TOMCATjsp代码:%@pagecontentType text/htmlcharsetGB2312 %%@pageimpor

有关一个注册问题
环境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)

不知道为什么,请高手帮解决,谢谢!!


------解决方案--------------------


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

热点排行