當前位置:首頁 » 網購平台 » 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的購物車(網上商店)系統源碼。擁有簡單的增刪改查登錄注冊就好。

源碼在此,採納即可