当前位置:首页 » 网购平台 » jsp购物车的增删改查
扩展阅读
宁波奥德赛优惠价格 2021-03-15 14:26:02
丹尼斯购物卡能挂失么 2021-03-15 14:25:58
淘宝购物指纹验证失败 2021-03-15 14:24:44

jsp购物车的增删改查

发布时间: 2021-02-06 22:01:13

① 用JSP做个网站实现购物车功能

建个购物车对象
把购买好的 商品 放到 一个 集合里

再把 集合 存到 session中
然后 增删改查 都 操作 session中的 集合
就OK了 不是很难 你试着 写下 这样 提高才会快

② 在jsp页面实现增删改查

那你要servlet 做说明用呢,你想要几个页面?具体情况看你的需求

③ JSP增删改查我在一个JSP里面设置修改按钮,在Dao.java里写了修改方法,大虾们看看我会追加分的!谢谢了

public void addshops(ShopInfo ui){
String sql = "update PerfectShop set 字段名=? where 字段名(主键)=?";
try{
pre = conn.prepareStatement(sql);
//设置相应的字段值
pre.setString(1,字段值);
int n = pre.executeUpate();
//可以根据n来判断是否执行成功回
}catch(Exception e){
e.printStackTrace();
}
}

另外你上面的rs = pre.executeQuery();
应该改成pre.executeUpdate();它返答回的是受影响的行数
查询的时候用executeQuery();

④ 如何在jsp中实现简单的部门信息增删改查(不需要数据库)

jsp中的增删改复查是通过操作特制定条件来实现动态改变Map的值来实现的。
比如根据部门id来查询:
定义一个存放部门信息的map,如下:
Map<integer,Dept> map=new HashMap<integer,Dept>();
查询方法:
Iterator keys = map.keySet().iterator();
while(keys.hasNext()){
String key = (String)keys.next();
if("id".equals(key)){
System.out.println("id为xx的员工信息");
}
}
添加是这样的map.put("001",new Dept());
删除是这样的map.remove();
更新是直接用map.put(key,value),这个方法会覆盖原来这个key对应的值,就相当于更新了

⑤ jsp增删改查怎么写

packagetest.;

importjava.sql.Connection;
importjava.sql.PreparedStatement;
importjava.sql.ResultSet;
importjava.sql.Statement;
importjava.util.ArrayList;
importjava.util.List;

importtest.entity.Emp;
importtest.util.BaseDao;

publicclassEmpDao{

//查找数据库Emp表所有人信息
publicList<Emp>findAll()throwsException{
nn=BaseDao.getCon();
Statementstat=conn.createStatement();
Stringsql="select*fromtblemp,tbldeptwheretbldept.deptid=tblemp.deptid";
ResultSetrs=stat.executeQuery(sql);
List<Emp>list=newArrayList<Emp>();
while(rs.next()){
Empe=newEmp();
e.setEmpid(rs.getInt("empid"));
e.setEname(rs.getString("ename"));
e.setDname(rs.getString("dname"));
list.add(e);
}
BaseDao.close(conn);
returnlist;
}

//往Emp表添加新员工
publicvoidsave(Empe)throwsException{
Connectionconn=BaseDao.getCon();
Stringsql="insertintotblemp(ename,egendar,deptid)values(?,?,?)";
PreparedStatementprep=conn.prepareStatement(sql);
prep.setString(1,e.getEname());
prep.setDouble(2,e.getEgendar());
prep.setInt(3,e.getDeptid());
prep.executeUpdate();
BaseDao.close(conn);
}

//根据id删除该员工
publicvoiddelete(intid)throwsException{
Connectionconn=BaseDao.getCon();
Stringsql="deletefromtblempwhereempid=?";
PreparedStatementprep=conn.prepareStatement(sql);
prep.setLong(1,id);
prep.executeUpdate();
BaseDao.close(conn);
}

//根据id查找该员工信息
publicEmpfindById(intid)throwsException{
Connectionconn=BaseDao.getCon();
Empe=null;
Stringsql="select*fromtblemp,tbldeptwhereempid=?andtbldept.deptid=tblemp.deptid";
PreparedStatementprep=conn.prepareStatement(sql);
prep.setLong(1,id);
ResultSetrs=prep.executeQuery();
if(rs.next()){
e=newEmp();
e.setEmpid(id);
e.setEname(rs.getString("ename"));
e.setEgendar(rs.getInt("egendar"));
e.setDname(rs.getString("dname"));
e.setDeptid(rs.getInt("deptid"));
}
returne;
}

//根据id修改该员工
publicvoipdate(Empe)throwsException{
Connectionconn=BaseDao.getCon();
Stringsql="updatetblempsetename=?,egendar=?,deptid=?whereempid=?";
PreparedStatementprep=conn.prepareStatement(sql);
prep.setString(1,e.getEname());
prep.setInt(2,e.getEgendar());
prep.setInt(3,e.getDeptid());
prep.setLong(4,e.getEmpid());
prep.executeUpdate();
BaseDao.close(conn);
}

}
//我把我写过的给你参考,你只需要修改成自己的字段就能用了。
需要用到哪个方法,就调用它。
EmpDao=newEmpDao();
//增加就.save(数据);
//删除就.delete(id);
//查找就.findAll();
//修改就.update(内容);

希望帮到你

⑥ 如何在JSP页面中实现对数据库的增删查改

首先我觉得你的问题不太明确,做增删改查,的话一般不用ajax,除非其中要用到内单独的验证字段的时候采用容,比如在注册时验证用户名,这里用到ajax查询用户名是否存在,返回给页面直接用流打回页面就行(比如:此用户名可用之类的)而其他的查询比如显示所有或者查询的结果为对象的话那看你用什么框架(controller),struts直接封装到值栈中,在页面用标签显示就行,不知道能不能帮到你

⑦ 通过JSP 调用SQL 增删改查方法,并且将结果返回到页面,怎么实现

在jsp页面顶部写上<%@page import=""%> import=你的赠删改查的类,比如在类中你有一个返回List的方法。在回页答面顶部导入类。在需要显示数据的地方写<% 实例化并接受你的非法返回的集合,然后显示出来 %> 剩下的你懂得。

⑧ 求jsp+javabean实现增删改查等操作

这是我以前写的代码,希望对你有所帮助,这是最基础的,以后学习hibernate框架的时候,代码就更加简单了,你也可以去学习下

/**
* 数据库
* **/
public class BaseDao {
public Connection connection() {
String forname = "oracle.jdbc.driver.OracleDriver";
String url = "jdbc:oracle:thin:@localhost:1521:uework";
String user = "epwork";
String pwd = "passowrd";
Connection conn = null;
try {
Class.forName(forname);
} catch (Exception e) {
System.err.print(e.getMessage());
}
try {
conn = DriverManager.getConnection(url, user, pwd);
} catch (SQLException e) {
System.err.print(e.getMessage());
}
return conn;
}
/**
*这里是关闭
**/
public void closeAll(Connection conn, ResultSet rs, PreparedStatement stmt) {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
System.err.print(e.getMessage());
}
}
if (stmt != null) {
try {
stmt.close();
} catch (SQLException e) {
System.err.print(e.getMessage());
}
}
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
System.err.print(e.getMessage());
}
}
}
}

/**
* 添加
* **/
public int addPingLun(pingluninfo pingluninfo) {
PreparedStatement stmt = null;
int rows = 0;
Connection conn = connection();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String sql = "insert into pingluninfo(Msgid,discussUserid,Msg,Msgtime,Rbid)values(seq_n.nextval,?,?,to_date(?,'yyyy-mm-dd hh24:mi:ss'),?)";
try {
stmt = conn.prepareStatement(sql);
stmt.setInt(1, pingluninfo.getDiscussUserid());
stmt.setString(2, pingluninfo.getMsg());
stmt.setString(3, sdf.format(pingluninfo.getMsgtime()));
stmt.setInt(4, pingluninfo.getRbid());
rows = stmt.executeUpdate();
if (rows <= 0) {
return -1;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
closeAll(conn, null, stmt);
}
return rows;
}

/**
* 查询
* **/
public List<Object> selPingLun(int Rbid, int pageSize,int pageIndex) {
PreparedStatement stmt = null;
ResultSet rs = null;
Connection conn = connection();
List<Object> pList = new ArrayList<Object>();
String sql =" select Msgid,discussUserid,Msg,Msgtime,Rbid from (select rownum as r,t.*from" +
"(select pingluninfo.*from pingluninfo " +
"where Rbid=? order by Msgtime desc) t" +
" where rownum <="+pageSize*pageIndex+") where r>"+pageSize*(pageIndex-1)+"";
try {
stmt = conn.prepareStatement(sql);
stmt.setInt(1, Rbid);
rs = stmt.executeQuery();
while (rs.next()) {
pingluninfo pingluninfo = new pingluninfo();
//List<Bifm> bList= new ArrayList<Bifm>();
Bifm bifm =new Bifm();
pingluninfo.setMsgid(rs.getInt("Msgid"));
pingluninfo.setDiscussUserid(rs.getInt("discussUserid"));
pingluninfo.setMsg(rs.getString("Msg"));
pingluninfo.setMsgtime(rs.getDate("Msgtime"));
pingluninfo.setRbid(rs.getInt("Rbid"));
String username=username(pingluninfo.getDiscussUserid());
bifm.setUsername("<a href=''>"+username+"</a>");
pingluninfo.setBifminfo(bifm);
pList.add(pingluninfo);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
closeAll(conn, rs, stmt);
}
return pList;
}

/**
* 修改
* **/
public int delFans(int userid, int fansuserid) {
PreparedStatement stmt = null;
Connection conn = connection();
int rows = 0;
String sql = "update receiveinfo set fansUserid=? where userid=? and fansuserid=?)";
try {
stmt = conn.prepareStatement(sql);
stmt.setString(1, null);
stmt.setInt(2, userid);
stmt.setInt(3, fansuserid);
rows = stmt.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
closeAll(conn, null, stmt);
}
return rows;
}

⑨ jsp怎么写增删改查代码

下面的代码即可实现(对数据库的操作):

<%@page
language="java"
contentType="text/html;charset=UTF-8"
pageEncoding="UTF-8"
%>
<%@pageimport="java.sql.*"%>
<center>
<H1><fontcolor="blue"size="12">管理中心</font></H1>
<HR/>
<tablewidth="80%"border="1">
<tr>
<th>ID</th>
<th>书名</th>
<th>作者</th>
<th>价格</th>
<th>删除</th>
</tr>
<%
//数据库的名字
StringdbName="zap";
//登录数据库的用户名
Stringusername="sa";
//登录数据库的密码
Stringpassword="123";
//数据库的IP地址,本机可以用localhost或者127.0.0.1
Stringhost="127.0.0.1";
//数据库的端口,一般不会修改,默认为1433
intport=1433;
StringconnectionUrl="jdbc:sqlserver://"+host+":"+port+";databaseName="+dbName+";user="+username
+";password="+password;
//
//声明需要使用的资源
//数据库连接,记得用完了一定要关闭
Connectioncon=null;
//Statement记得用完了一定要关闭
Statementstmt=null;
//结果集,记得用完了一定要关闭
ResultSetrs=null;
try{
//注册驱动
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
//获得一个数据库连接
con=DriverManager.getConnection(connectionUrl);

StringSQL="SELECT*fromnote";
//创建查询
stmt=con.createStatement();
//执行查询,拿到结果集
rs=stmt.executeQuery(SQL);
while(rs.next()){
%>
<tr>
<td>
<%=rs.getInt(1)%>
</td>
<td>
<ahref="prepareupdate?ID=<%=rs.getInt("ID")%>"target="_blank"><%=rs.getString(2)%></a>
</td>
<td>
<%=rs.getString(3)%>
</td>
<td>
<%=rs.getString(4)%>
</td>
<td>
<ahref="delete?ID=<%=rs.getInt("ID")%>"target="_blank">删除</a>
</td>
</tr>
<%
}
}catch(Exceptione){
//捕获并显示异常
e.printStackTrace();
}finally{
//关闭我们使用过的资源
if(rs!=null)
try{
rs.close();
}catch(Exceptione){}
if(stmt!=null)
try{
stmt.close();
}catch(Exceptione){}
if(con!=null)
try{
con.close();
}catch(Exceptione){}
}
%>
</table>
<ahref="insert.jsp">添加新纪录</a>
</center>

⑩ 求一份jsp+ mysql的购物车(网上商店)系统源码。拥有简单的增删改查登录注册就好。

源码在此,采纳即可