无法写入数据库,求大神帮忙解决啊,急急急,感激不尽啊!!!!!!!!

package com.servlet;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import com.Bean.*;

public class addaction extends HttpServlet
{
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws IOException,ServletException
{
response.setContentType("text/html;charset=gb2312");
request.setCharacterEncoding("GBK");
PrintWriter out=response.getWriter();

    boolean flag=false;

    String gdbID ,gname,gpricestr,gnumstr,gmaker,gintro;

    gdbID=request.getParameter("gdbID");
    gname=request.getParameter("gname");
    gpricestr=request.getParameter("gprice");
    gnumstr=request.getParameter("gnum");
    gmaker=request.getParameter("gmaker");
    gintro=request.getParameter("gintro");

    System.out.println(gdbID);
    System.out.println(gname);
    System.out.println(gpricestr);
    System.out.println(gnumstr);
    System.out.println(gmaker);
    System.out.println(gintro);



    int gprice=Integer.parseInt(gpricestr);
    int gnum=Integer.parseInt(gnumstr);
    dbconn dbcon=new dbconn();

    String insertStr="insert into goodsInfo(gdbID,gname,gprice,gnum,gmaker,gintro) values";
    insertStr=insertStr+"('"+gdbID+"',";
    insertStr=insertStr+"('"+gname+"',";
    insertStr=insertStr+""+gprice+",";
    insertStr=insertStr+""+gnum+",";
    insertStr=insertStr+"'"+gmaker+"',";
    insertStr=insertStr+"'"+gintro+"')";

    //out.println(insertStr);
    try
    {
        flag=dbcon.executeUpdate(insertStr);
        dbcon.destory();
    }
    catch(Exception e)
    {
        out.println(e.getMessage());
    }
    if(flag)
    {
        out.println("<script language=\"javascript\">alert(\"添加成功\");window.history.go(-1);</script>");
        /*getServletConfig().getServletContext().getRequestDispatcher("/listaction").forward(request,response);*/

    }
    else
    {
        getServletConfig().getServletContext().getRequestDispatcher("/error.jsp").forward(request,response);

    }
}

}

查看全部
qq_35787129
qq_35787129
2016/08/04 02:17
  • 点赞
  • 收藏
  • 回答
    私信

5个回复