📄 carcheck.jsp
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" contentType="text/html; charset=gb2312"
pageEncoding="gb2312" import="java.sql.*"%>
<jsp:useBean id="check" class="Bean.DbConn" scope="request"/>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<%
ResultSet rs=null;
int i=0;//
int getId=0;//用于存储汽车的品牌号
String strSql2="";
request.setCharacterEncoding("GBK");//解决表单传来的汉字问题
//判断是否单击了完成按钮
String brandname=request.getParameter("brandname");//获取表单信息
String type=request.getParameter("type");
String price=request.getParameter("price");
String prodtime=request.getParameter("prodtime");
String cover=request.getParameter("cover");
String manufacturer=request.getParameter("manufacturer");
String introduction=request.getParameter("introduction");
String commend=request.getParameter("commend");
String strSql="select * from category where bname='"+brandname+"'";
String strSql1="insert into category(bname) values('"+brandname+"')";
check.open();//链接数据库
rs=check.executeQuery(strSql);//查询库中是否有该汽车的品牌
if(rs.next())
{
rs=check.executeQuery(strSql);
if(rs.next()) getId=rs.getInt(1);
String str="select * from category,car where category.brand_id='"+getId+"' and type='"+type+"' and category.brand_id=car.brand_id";
rs=check.executeQuery(str);
if(rs.next())
{
out.println("<script>alert('该品牌已有这种型号的车,请换过一个!');window.history.go(-1);</script>");
}
else
{
int m=0;
String strSql3="";
if(commend!=null)//若推荐,则直接插入,否则须将另外一个值赋给commend,因为如果commend为空的话,数据库是不认null值的
strSql3="insert into car(brand_id,type,price,prodtime,cover,manufacturer,introduction) values("+getId+",'"+type+"','"+price+"','"+prodtime+"','"+cover+"','"+manufacturer+"','"+introduction+"')";
else
strSql3="insert into car(brand_id,type,price,prodtime,cover,manufacturer,introduction,commend) values("+getId+",'"+type+"','"+price+"','"+prodtime+"','"+cover+"','"+manufacturer+"','"+introduction+"','否')";
m=check.executeUpdate(strSql3);
if(m!=0)
out.println("<script>alert('添加汽车成功!');window.location='right.html';</script>");
}
}
else//若没有,则将之插入car表中
{
int j=0,z=0;
j=check.executeUpdate(strSql1);//将该品牌名插入到category中
rs=check.executeQuery(strSql);//获取该品牌名在category中的品牌号,以便下面容易将之插入到car表中
if(rs.next()) getId=rs.getInt(1);
if(commend!=null)//若推荐,则直接插入,否则须将另外一个值赋给commend,因为如果commend为空的话,数据库是不认null值的
strSql2="insert into car(brand_id,type,price,prodtime,cover,manufacturer,introduction) values("+getId+",'"+type+"','"+price+"','"+prodtime+"','"+cover+"','"+manufacturer+"','"+introduction+"')";
else
strSql2="insert into car(brand_id,type,price,prodtime,cover,manufacturer,introduction,commend) values("+getId+",'"+type+"','"+price+"','"+prodtime+"','"+cover+"','"+manufacturer+"','"+introduction+"','否')";
z=check.executeUpdate(strSql2);
if(j!=0&&z!=0)
out.println("<script>alert('添加汽车成功!');window.location='right.html';</script>");
}
%>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -