u013319244
William Jing
2016-04-07 05:14

mysql数据可以读取,但是不能写入

  • java
  • mysql
  • eclipse

myeclipse下的web应用
有一个登录注册功能,登陆的时候读取数据库可以,
但是注册要写入进去就不行

register.jsp
 <%@ page language="java" import="java.util.*,java.sql.*,cn.edu.dhu.*"%>
<%@ page contentType="text/html,charset=utf-8" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->

  </head>
    <%
        String name = request.getParameter("usernamesignup");
        String account = request.getParameter("emailsignup");
        String pswd1 =  request.getParameter("passwordsignup");
        String pswd2 =  request.getParameter("passwordsignup_confirm");

        System.out.println("name="+name);
        System.out.println("name="+account);
        System.out.println("name="+pswd1);
        System.out.println("name="+pswd2);

        if(account !=null && pswd2!=null){
            System.out.println("执行到了");
            String sql = "use jsgl;insert into jsgl.user values('"+name+"','"+account+"','"+pswd1+"','"+pswd2+"')";
            System.out.println("执行到了");
            Connection conn=DB.getConn();
            System.out.println("执行到了");
            Statement stmt = DB.createStmt(conn);
            System.out.println("执行到了");
            int n = DB.executeUpdate(stmt, sql);
            response.sendRedirect("index.jsp");
            System.out.println("执行到了");
        }

     %>
  <body>

  </body>
</html>

图片说明
都执行到了,但是数据库里面没有信息

ps:从命令行敲insert语句是可以插入的 myeclipse这里不行的
求帮忙

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

4条回答