jsp向mysql插入记录的问题

WBOY
풀어 주다: 2016-06-06 09:43:35
원래의
904명이 탐색했습니다.

mysqljspsql

通过第一个页面向第二个页面post文本框的值,然后通过第二个页面向数据库添加信息
第一个页面的代码如下 function Judge()
{if(document.form.p_name.value=="")
{window.alert("产品名称不能为空!");document.form.p_name.focus();return false;}
if(document.form.p_type.value=="")
{window.alert("产品类型不能为空!");document.form.p_type.focus();return false;}
}









第二个页面代码为
try {Class.forName("com.mysql.jdbc.Driver");}
catch(Exception e){e.printStackTrace();}
Connection conn;ResultSet rs;Statement stmt;
try
{String database="mydb";
String url="jdbc:mysql://localhost:3306/"+database;
conn=DriverManager.getConnection(url,"root","root");
String name=request.getParameter("p_name");
String type=request.getParameter("p_type");
String detail=request.getParameter("p_detail");
stmt=conn.createStatement();
String sql="insert into product(p_name,p_type,p_detail)values('"+name+"','"+type+"','"+detail+"')";
stmt.executeUpdate(sql);
int i=stmt.executeUpdate(sql);
if(i!=0){out.print("添加成功");response.setHeader("refresh", "2;URL=addproduct2.jsp");}
else{out.print("添加失败");response.setHeader("refresh", "2;URL=addproduct2.jsp");}
}
catch(Exception e){e.printStackTrace();
out.print("
");<br>e.printStackTrace(new java.io.PrintWriter(out));<br>out.print("
로그인 후 복사
");}

%>

为啥输入产品123 类型123会向数据库中添加两条一模一样的记录呢,问题出在哪里

产品名称
产品类型
产品详情
产品图片
관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!