shopcartdao.java
来自「网上书店后台管理源码基于struts1.2+oracle数据库」· Java 代码 · 共 102 行
JAVA
102 行
package com.dongfang.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import com.dongfang.vo.ShopCart;
public class ShopCartDAO {
public int getNextId()
{
int myID = 0;
Connection conn = null;
Statement stm = null;
ResultSet rs = null;
conn = Tools.getConn();
try {
stm = conn.createStatement();
rs = stm.executeQuery("select max(id) id from shopcart");
if(rs.next())
{
myID = rs.getInt("id");
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
try {
if(rs!=null)
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
if(stm!=null)
stm.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
if(conn!=null)
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return ++myID;
}
public boolean saveShopCart(ShopCart shopCart)
{
boolean isSaved =false;
Connection conn = null;
PreparedStatement pstmt = null;
conn = Tools.getConn();
String sql = "insert into shopcart values(?,?,?,?)";
try {
pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, shopCart.getId());
pstmt.setInt(2, shopCart.getOrderId());
pstmt.setInt(3, shopCart.getBook().getId());
pstmt.setDouble(4, shopCart.getPrice());
int temp = pstmt.executeUpdate();
if(temp>0)
{
isSaved = true;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
try {
if(pstmt!=null)
pstmt.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
if(conn!=null)
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return isSaved;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?