JSP SERVLET JDBC实现对数据库的增删改查课案Word文档格式.docx
- 文档编号:14347881
- 上传时间:2022-10-22
- 格式:DOCX
- 页数:31
- 大小:385.25KB
JSP SERVLET JDBC实现对数据库的增删改查课案Word文档格式.docx
《JSP SERVLET JDBC实现对数据库的增删改查课案Word文档格式.docx》由会员分享,可在线阅读,更多相关《JSP SERVLET JDBC实现对数据库的增删改查课案Word文档格式.docx(31页珍藏版)》请在冰豆网上搜索。
packagebean;
publicclassPage{
privateinttotalPage;
privateintcurrentPage;
privateinttotalRecord;
privateintcurrentRecord;
privateintpageSize=8;
//获得和设置当前页
publicintgetCurrentPage(){
returncurrentPage;
}
publicvoidsetCurrentPage(intcurrentRecord,intpageSize){
if(currentRecord%pageSize==0){
currentPage=currentRecord/pageSize;
}
else{
currentPage=currentRecord/pageSize+1;
//获得和设置当前记录
publicintgetCurrentRecord(){
returncurrentRecord;
publicvoidsetCurrentRecord(intcurrentRecord){
this.currentRecord=currentRecord;
//获得和设置每页记录数量
publicintgetPageSize(){
returnpageSize;
publicvoidsetPageSize(intpageSize){
this.pageSize=pageSize;
//获得和设置总页数
publicintgetTotalPage(){
returntotalPage;
publicvoidsetTotalPage(inttotalRecord,intpageSize){
if(totalRecord%pageSize==0){
totalPage=totalRecord/pageSize;
totalPage=totalRecord/pageSize+1;
//获得和设置总记录
publicintgetTotalRecord(){
returntotalRecord;
publicvoidsetTotalRecord(inttotalRecord){
this.totalRecord=totalRecord;
}
8,用相同的方法建一个StudentInfo类
完整的StudentInfo.java代码如下
publicclassStudentInfo{
privateintid;
//学号
privateStringname;
//姓名
privateintage;
//年龄
privateStringgender;
//性别
privateStringmajor;
//专业
publicStudentInfo(){
publicStudentInfo(intid,Stringname,intage,Stringgender,Stringmajor){
this.id=id;
this.name=name;
this.age=age;
this.gender=gender;
this.major=major;
publicintgetId(){
returnid;
publicvoidsetId(intid){
publicStringgetName(){
returnname;
publicvoidsetName(Stringname){
publicintgetAge(){
returnage;
publicvoidsetAge(intage){
publicStringgetGender(){
returngender;
publicvoidsetGender(Stringgender){
publicStringgetMajor(){
returnmajor;
publicvoidsetMajor(Stringmajor){
9,在src目录下添加另一个包dbservlet在该包中建立一个AllServlet类
完整的AllServlet.java代码如下
packagedbservlet;
importjava.io.IOException;
importjava.sql.Connection;
importjava.sql.DriverManager;
importjava.sql.ResultSet;
importjava.sql.SQLException;
importjava.sql.Statement;
importjava.util.ArrayList;
importjava.util.List;
importjavax.servlet.ServletException;
importjavax.servlet.http.HttpServlet;
importjavax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;
importbean.Page;
importbean.StudentInfo;
publicclassAllServletextendsHttpServlet{
/**
*
*/
privatestaticfinallongserialVersionUID=1L;
//doPost方法
publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)
throwsServletException,IOException{
request.setCharacterEncoding("
UTF-8"
);
response.setCharacterEncoding("
StringmethodName=request.getParameter("
methodName"
intmethod=Integer.parseInt(methodName);
try{
switch(method)
{
case0:
insert(request,response);
case1:
difpage(request,response);
break;
case2:
delete(request,response);
break;
case3:
update(request,response);
break;
case4:
update1(request,response);
case5:
dispatch(request,response);
}catch(ClassNotFoundExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}catch(SQLExceptione){
}
//doGet方法
publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)
throwsServletException,IOException{
doPost(request,response);
//数据库连接方法
publicConnectionconnect()throwsClassNotFoundException,SQLException{
Connectionconn=null;
Class.forName("
oracle.jdbc.driver.OracleDriver"
Stringurl="
jdbc:
oracle:
thin:
@localhost:
1521:
orcl"
;
Stringuser="
scott"
Stringpassword="
tiger"
conn=DriverManager.getConnection(url,user,password);
returnconn;
//关闭数据库资源
publicvoidclose(Statementstat,Connectionconn)throwsSQLException{
if(stat!
=null){
stat.close();
if(conn!
conn.close();
//插入方法
publicvoidinsert(HttpServletRequestrequest,HttpServletResponseresponse)throwsClassNotFou
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- JSP SERVLET JDBC实现对数据库的增删改查课案 JDBC 实现 数据库 增删 改查课案