?? smalltypedao.java
字號:
package com.wy.dao;
import com.wy.tool.JDBConnection;
import java.sql.*;
import java.util.*;
import com.wy.domain.SmallTypeForm;
//對商品小類別信息的操作
public class SmallTypeDao {
private Connection connection = null; // 定義連接的對象
private PreparedStatement ps = null; // 定義預準備的對象
private JDBConnection jdbc = null; // 定義數據庫連接對象
public SmallTypeDao() {
jdbc = new JDBConnection();
connection = jdbc.connection; // 利用構造方法取得數據庫連接
}
// 以小類別外關鍵為條件查詢信息
public List selectOneBigId(Integer bigId) {
List list = new ArrayList();
SmallTypeForm small = null;
try {
this.ps = connection
.prepareStatement("select * from tb_smallType where bigId=?");
ps.setString(1, bigId.toString());
ResultSet rs = ps.executeQuery();
while (rs.next()) {
small = new SmallTypeForm();
small.setId(Integer.valueOf(rs.getString(1)));
small.setBigId(Integer.valueOf(rs.getString(2)));
small.setSmallName(rs.getString(3));
small.setCreaTime(rs.getString(4));
list.add(small);
}
} catch (SQLException ex) {
}
return list;
}
// 以數據庫流水號為條件查詢小類別的名稱
public String selectName(Integer id) {
String name = null;
try {
this.ps = connection
.prepareStatement("select * from tb_smallType where id=?");
ps.setString(1, id.toString());
ResultSet rs = ps.executeQuery();
while (rs.next()) {
name = rs.getString("smallName");
}
} catch (SQLException ex) {
}
return name;
}
// 刪除操作
public boolean deleteSmall(Integer id) {
try {
ps = connection.prepareStatement("delete from tb_smallType where id=?");
ps.setString(1, id.toString());
ps.executeUpdate();
ps.close();
return true;
} catch (SQLException ex) {
return false;
}
}
// 修改操作
public void updateSmall(SmallTypeForm form) {
try {
ps = connection.prepareStatement("update tb_smallType set bigId=?,smallName=? where id=?");
ps.setString(1, form.getBigId().toString());
ps.setString(2, form.getSmallName());
ps.setString(3, form.getId().toString());
ps.executeUpdate();
ps.close();
} catch (SQLException ex) {
}
}
// 添加操作
public void insertSmall(SmallTypeForm form) {
try {
ps = connection.prepareStatement("insert into tb_smallType values (?,?,getDate())");
ps.setString(1, form.getBigId().toString());
ps.setString(2, form.getSmallName());
ps.executeUpdate();
ps.close();
} catch (SQLException ex) {
}
}
// 以數據庫流水號為條件查詢信息
public SmallTypeForm selectOneBig(Integer id) {
SmallTypeForm small = null;
try {
this.ps = connection
.prepareStatement("select * from tb_smallType where id=?");
ps.setString(1, id.toString());
ResultSet rs = ps.executeQuery();
while (rs.next()) {
small = new SmallTypeForm();
small.setId(Integer.valueOf(rs.getString(1)));
small.setBigId(Integer.valueOf(rs.getString(2)));
small.setSmallName(rs.getString(3));
small.setCreaTime(rs.getString(4));
}
} catch (SQLException ex) {
}
return small;
}
// 全部查詢的操作
public List selectSmall() {
List list = new ArrayList();
SmallTypeForm small = null;
try {
this.ps = connection.prepareStatement("select * from tb_smallType order by id DESC");
ResultSet rs = ps.executeQuery();
while (rs.next()) {
small = new SmallTypeForm();
small.setId(Integer.valueOf(rs.getString(1)));
small.setBigId(Integer.valueOf(rs.getString(2)));
small.setSmallName(rs.getString(3));
small.setCreaTime(rs.getString(4));
list.add(small);
}
} catch (SQLException ex) {
}
return list;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -