java增删改查+分页操作
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
return courlist;
}
//分页
public PageModel<Course> findCourAll(Connection conn, int currentPage,
int pageSize) {
String sql="select * from Course limit ?,?";
ProfId = profId;
}
public String getProfName() {
return ProfName;
}
public void setProfName(String profName) {
ProfName = profName;
}
public String getProfNumber() {
ProfId = profId;
}
public String getCourseName() {
return CourseName;
}
public void setCourseName(String courseName) {
CourseName = courseName;
}
}
package com.pro.domain;
public Course findCourById(Connection conn,int CourseId);
public List<Course> findCourAll(Connection conn);
public List<Course> findByProId(Connection conn,int ProfId);
}
public Course findCourById(Connection conn, int CourseId) {
String sql="select * from Course where CourseId=?";
Object[] param={CourseId};
ResultSet rs=this.getRs(conn, sql, param);
public PageModel<Course> findCourAll(Connection conn,int currentPage,int pageSize);
}
package com.pro.courdao;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.pro.domain.Course;
import com.pro.profdao.BaseDao;
import com.pro.util.PageModel;
public void add(Connection conn,Course cour);
public void deleteCourById(Connection conn,int CourseId);
public void update(Connection conn,Course cour);
ResultSet rs=this.getRs(conn, sql, param);
List<Course> courlist=new ArrayList<Course>();
Course cour =null;
try {
while(rs.next()){
cour = new Course();
cour.setCourseId(rs.getInt("CourseId"));
return ProfNumber;
}
public void setProfNumber(String profNumber) {
ProfNumber = profNumber;
}
}
package com.pro.profdao;
import java.sql.Connection;
import java.sql.PreparedStatement;
public class CourDaoImpl extends BaseDao implements CourDao {
public void add(Connection conn, Course cour) {
String sql="insert into Course(CourseId,ProfId,CourseName) values(?,?,?)";
cour.setProfId(rs.getInt("ProfId"));
cour.setCourseName(rs.getString("CourseName"));
courlist.add(cour);
}
} catch (SQLException e) {
e.printStackTrace();
}
return pagemodel;
}
//关联ห้องสมุดไป่ตู้询的语句
public List<Course> findByProId(Connection conn, int ProfId) {
String sql="select * from Course where Profid=?";
Object[] param={ProfId};
ResultSet rs=this.getRs(conn, sql, param);
List<Course> courlist = new ArrayList<Course>();
try {
while(rs.next()){
Course cour = new Course();
cour.setCourseId(rs.getInt("CourseId"));
Course cour =null;
try {
while(rs.next()){
cour = new Course();
cour.setCourseId(rs.getInt("CourseId"));
cour.setProfId(rs.getInt("ProfId"));
cour.setCourseName(rs.getString("CourseName"));
public class Profession {
private int ProfId;
private String ProfName;
private String ProfNumber;
public int getProfId() {
return ProfId;
}
public void setProfId(int profId) {
courlist.add(cour);
}
} catch (SQLException e) {
e.printStackTrace();
}
PageModel<Course> pagemodel = new PageModel<Course>();
pagemodel.setList(courlist);
pagemodel.setCurrentPage(currentPage);
try {
pstmt=conn.prepareStatement(sql);
if(param !=null){
for(int i=0;i<param.length;i++){
pstmt.setObject(i+1, param[i]);
}
}
pstmt.executeUpdate();
} catch (SQLException e) {
pagemodel.setPageSize(pageSize);
String sqlCount="select count(*) from Course";
int totalRecord = this.getRowCount(conn, sqlCount, null);
pagemodel.setTotalRecord(totalRecord);
Course cour = new Course();
cour.setCourseId(rs.getInt("CourseId"));
cour.setProfId(rs.getInt("ProfId"));
cour.setCourseName(rs.getString("CourseName"));
String sql="delete from Course where CourseId=?";
Object[] param={CourseId};
this.exeSql(conn, sql, param);
}
public void update(Connection conn, Course cour) {
Object[] param={(currentPage-1)*pageSize,pageSize};
ResultSet rs=this.getRs(conn, sql, param);
List<Course> courlist = new ArrayList<Course>();
try {
while(rs.next()){
e.printStackTrace();
}
}
//查询
public ResultSet getRs(Connection conn,String sql,Object[] param){
Object[] param={cour.getCourseId(),cour.getProfId(),cour.getCourseName()};
this.exeSql(conn, sql, param);
}
public void deleteCourById(Connection conn, int CourseId) {
String sql="update Course set CourseName=?,ProfId=? where CourseId=?";
Object[] param={cour.getCourseName(),cour.getProfId(),cour.getCourseId()};
this.exeSql(conn, sql, param);
package com.pro.courdao;
import java.sql.Connection;
import java.util.List;
import com.pro.domain.Course;
import com.pro.util.PageModel;
public interface CourDao {
}
} catch (SQLException e) {
e.printStackTrace();
}
return cour;
}
public List<Course> findCourAll(Connection conn) {
String sql="select * from Course";
Object[] param={};
return CourseId;
}
public void setCourseId(int courseId) {
CourseId = courseId;
}
public int getProfId() {
return ProfId;
}
public void setProfId(int profId) {
import java.sql.ResultSet;
import java.sql.SQLException;
public class BaseDao {
//增删改
public void exeSql(Connection conn,String sql,Object[] param){
PreparedStatement pstmt = null;
return courlist;
}
}
package com.pro.domain;
public class Course {
private int CourseId;
private int ProfId;
private String CourseName;
public int getCourseId() {
cour.setProfId(rs.getInt("ProfId"));
cour.setCourseName(rs.getString("CourseName"));
courlist.add(cour);
}
} catch (SQLException e) {
e.printStackTrace();
}
}
//分页
public PageModel<Course> findCourAll(Connection conn, int currentPage,
int pageSize) {
String sql="select * from Course limit ?,?";
ProfId = profId;
}
public String getProfName() {
return ProfName;
}
public void setProfName(String profName) {
ProfName = profName;
}
public String getProfNumber() {
ProfId = profId;
}
public String getCourseName() {
return CourseName;
}
public void setCourseName(String courseName) {
CourseName = courseName;
}
}
package com.pro.domain;
public Course findCourById(Connection conn,int CourseId);
public List<Course> findCourAll(Connection conn);
public List<Course> findByProId(Connection conn,int ProfId);
}
public Course findCourById(Connection conn, int CourseId) {
String sql="select * from Course where CourseId=?";
Object[] param={CourseId};
ResultSet rs=this.getRs(conn, sql, param);
public PageModel<Course> findCourAll(Connection conn,int currentPage,int pageSize);
}
package com.pro.courdao;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.pro.domain.Course;
import com.pro.profdao.BaseDao;
import com.pro.util.PageModel;
public void add(Connection conn,Course cour);
public void deleteCourById(Connection conn,int CourseId);
public void update(Connection conn,Course cour);
ResultSet rs=this.getRs(conn, sql, param);
List<Course> courlist=new ArrayList<Course>();
Course cour =null;
try {
while(rs.next()){
cour = new Course();
cour.setCourseId(rs.getInt("CourseId"));
return ProfNumber;
}
public void setProfNumber(String profNumber) {
ProfNumber = profNumber;
}
}
package com.pro.profdao;
import java.sql.Connection;
import java.sql.PreparedStatement;
public class CourDaoImpl extends BaseDao implements CourDao {
public void add(Connection conn, Course cour) {
String sql="insert into Course(CourseId,ProfId,CourseName) values(?,?,?)";
cour.setProfId(rs.getInt("ProfId"));
cour.setCourseName(rs.getString("CourseName"));
courlist.add(cour);
}
} catch (SQLException e) {
e.printStackTrace();
}
return pagemodel;
}
//关联ห้องสมุดไป่ตู้询的语句
public List<Course> findByProId(Connection conn, int ProfId) {
String sql="select * from Course where Profid=?";
Object[] param={ProfId};
ResultSet rs=this.getRs(conn, sql, param);
List<Course> courlist = new ArrayList<Course>();
try {
while(rs.next()){
Course cour = new Course();
cour.setCourseId(rs.getInt("CourseId"));
Course cour =null;
try {
while(rs.next()){
cour = new Course();
cour.setCourseId(rs.getInt("CourseId"));
cour.setProfId(rs.getInt("ProfId"));
cour.setCourseName(rs.getString("CourseName"));
public class Profession {
private int ProfId;
private String ProfName;
private String ProfNumber;
public int getProfId() {
return ProfId;
}
public void setProfId(int profId) {
courlist.add(cour);
}
} catch (SQLException e) {
e.printStackTrace();
}
PageModel<Course> pagemodel = new PageModel<Course>();
pagemodel.setList(courlist);
pagemodel.setCurrentPage(currentPage);
try {
pstmt=conn.prepareStatement(sql);
if(param !=null){
for(int i=0;i<param.length;i++){
pstmt.setObject(i+1, param[i]);
}
}
pstmt.executeUpdate();
} catch (SQLException e) {
pagemodel.setPageSize(pageSize);
String sqlCount="select count(*) from Course";
int totalRecord = this.getRowCount(conn, sqlCount, null);
pagemodel.setTotalRecord(totalRecord);
Course cour = new Course();
cour.setCourseId(rs.getInt("CourseId"));
cour.setProfId(rs.getInt("ProfId"));
cour.setCourseName(rs.getString("CourseName"));
String sql="delete from Course where CourseId=?";
Object[] param={CourseId};
this.exeSql(conn, sql, param);
}
public void update(Connection conn, Course cour) {
Object[] param={(currentPage-1)*pageSize,pageSize};
ResultSet rs=this.getRs(conn, sql, param);
List<Course> courlist = new ArrayList<Course>();
try {
while(rs.next()){
e.printStackTrace();
}
}
//查询
public ResultSet getRs(Connection conn,String sql,Object[] param){
Object[] param={cour.getCourseId(),cour.getProfId(),cour.getCourseName()};
this.exeSql(conn, sql, param);
}
public void deleteCourById(Connection conn, int CourseId) {
String sql="update Course set CourseName=?,ProfId=? where CourseId=?";
Object[] param={cour.getCourseName(),cour.getProfId(),cour.getCourseId()};
this.exeSql(conn, sql, param);
package com.pro.courdao;
import java.sql.Connection;
import java.util.List;
import com.pro.domain.Course;
import com.pro.util.PageModel;
public interface CourDao {
}
} catch (SQLException e) {
e.printStackTrace();
}
return cour;
}
public List<Course> findCourAll(Connection conn) {
String sql="select * from Course";
Object[] param={};
return CourseId;
}
public void setCourseId(int courseId) {
CourseId = courseId;
}
public int getProfId() {
return ProfId;
}
public void setProfId(int profId) {
import java.sql.ResultSet;
import java.sql.SQLException;
public class BaseDao {
//增删改
public void exeSql(Connection conn,String sql,Object[] param){
PreparedStatement pstmt = null;
return courlist;
}
}
package com.pro.domain;
public class Course {
private int CourseId;
private int ProfId;
private String CourseName;
public int getCourseId() {
cour.setProfId(rs.getInt("ProfId"));
cour.setCourseName(rs.getString("CourseName"));
courlist.add(cour);
}
} catch (SQLException e) {
e.printStackTrace();
}