JSP SERVLET JDBC实现对数据库的增删改查课案Word文档格式.docx

上传人:b****3 文档编号:14347881 上传时间:2022-10-22 格式:DOCX 页数:31 大小:385.25KB
下载 相关 举报
JSP SERVLET JDBC实现对数据库的增删改查课案Word文档格式.docx_第1页
第1页 / 共31页
JSP SERVLET JDBC实现对数据库的增删改查课案Word文档格式.docx_第2页
第2页 / 共31页
JSP SERVLET JDBC实现对数据库的增删改查课案Word文档格式.docx_第3页
第3页 / 共31页
JSP SERVLET JDBC实现对数据库的增删改查课案Word文档格式.docx_第4页
第4页 / 共31页
JSP SERVLET JDBC实现对数据库的增删改查课案Word文档格式.docx_第5页
第5页 / 共31页
点击查看更多>>
下载资源
资源描述

JSP SERVLET JDBC实现对数据库的增删改查课案Word文档格式.docx

《JSP SERVLET JDBC实现对数据库的增删改查课案Word文档格式.docx》由会员分享,可在线阅读,更多相关《JSP SERVLET JDBC实现对数据库的增删改查课案Word文档格式.docx(31页珍藏版)》请在冰豆网上搜索。

JSP SERVLET JDBC实现对数据库的增删改查课案Word文档格式.docx

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

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 经管营销

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1