📄 contenttypedaoimpl.java
字号:
package com.myContent.dao.impl;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import com.myContent.vo.ContentType;
import com.myContent.dao.ContentTypeDAO;
import com.gd.jdbc.impl.GdDbCommon;
public class ContentTypeDAOImpl extends GdDbCommon implements ContentTypeDAO {
/**
* 构造函数
* @param conn
*/
public ContentTypeDAOImpl(Connection conn) {
super(conn);
}
/**
* 根据Object实现新增
*/
public int createContentType(ContentType contentType) throws SQLException{
String sql = "insert into contentType (contentTypeId, contentTypeName) values(?, ?)";
this.PreparedStatement(sql);
this.setString(1, contentType.getContentTypeId());
this.setString(2, contentType.getContentTypeName());
return this.executeUpdate();
}
/**
* 根据Object实现修改
*/
public int updateContentType(ContentType contentType) throws SQLException {
String sql = "update contentType set contentTypeName = ? where contentTypeId = ? ";
this.PreparedStatement(sql);
this.setString(1, contentType.getContentTypeName());
this.setString(2, contentType.getContentTypeId());
return this.executeUpdate();
}
/**
* 根据Object实现删除
*/
public int deleteContentType(ContentType contentType) throws SQLException{
String sql = "delete from contentType where contentTypeId = ?";
this.PreparedStatement(sql);
this.setString(1, contentType.getContentTypeId());
return this.executeUpdate();
}
/**
* 根据contentTypeId查询Object
*/
public ContentType queryContentType(String contentTypeId) throws SQLException{
String sql = "select * from contentType where contentTypeId = ?";
this.PreparedStatement(sql);
this.setString(1, contentTypeId);
return (ContentType)this.queryObj();
}
/**
* 根据Object实现批量新增
*/
public int createListContentType(List list) throws SQLException{
String sql = "insert into contentType (contentTypeId, contentTypeName) values(?, ?)";
this.PreparedStatement(sql);
ContentType contentType = null;
int counts = 0;
for (int i = 0; list != null && list.size() > i; i++) {
contentType = (ContentType)list.get(i);
this.setString(1, contentType.getContentTypeId());
this.setString(2, contentType.getContentTypeName());
counts += this.executeUpdate();
}
return counts;
}
/**
* 根据Object实现批量新增,使用batch方式
*/
public int[] createBatchListContentType(List list) throws SQLException{
String sql = "insert into contentType (contentTypeId, contentTypeName) values(?, ?)";
this.PreparedStatement(sql);
ContentType contentType = null;
int counts = 0;
for (int i = 0; list != null && list.size() > i; i++) {
contentType = (ContentType)list.get(i);
this.setString(1, contentType.getContentTypeId());
this.setString(2, contentType.getContentTypeName());
this.addBatch();
}
return this.executeBatch();
}
/**该方法用来获取所有的内容类别
*/
public List queryAllContentType() throws Exception {
String sql = "select * from contentType";
this.PreparedStatement(sql);
return this.queryAllObj();
}
// 重载getObjFromRs方法
protected ContentType getObjFromRs(ResultSet rs) throws SQLException {
ContentType contentType = new ContentType();
contentType.setId(rs.getInt("id"));
contentType.setContentTypeId(rs.getString("contentTypeId"));
contentType.setContentTypeName((rs.getString("contentTypeName")));
return contentType;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -