关键词不能为空

当前您在: 主页 > 英语 >

南昌航空大学实验报告2-JavaBean和Servlet完成增删改查

作者:高考题库网
来源:https://www.bjmy2z.cn/gaokao
2021-02-15 14:37
tags:

-

2021年2月15日发(作者:abrogate)


南昌航空大学实验报告二




0


一四












十九







课程名称:








JA


V


A WEB


程序设计







实验名称:








JavaBean



Servlet


完成增删改查






班级:




11


微软班







姓名:




林平君








同组人:































指导教师评定:










林振荣



























签名:






















一、



实验目的



完成一个数据列表的增删改 查功能的实现,以自己创建的表格为例,也可以自己设计数据库的表。通


过本实验能够熟 悉和掌握


jsp


中的数据库


CRUD< /p>


操作。



二、



实验要求



本实验要求通过

< p>
javabean


来实现数据的存取和表示,


通过


servlet


来进行访问的控制。


给 出主要运行的界面


和核心代码,并描述系统实现的核心思想。



三、



实验步骤



1




实现< /p>


javaBean


对数据库的操作。



2




创建< /p>


jsp


页面



3




利用< /p>


servlet


对页面对业务流程就行控制。


四、



参考源代码



1.



连接数据库



public


Connection getConnection()


throws



SQLException,InstantiationException,




IllegalAccessEx ception,ClassNotFoundException{




Connection connection=


null


;




Class.


forName


(



).newInst


ance();




String


urlString=



;




String passwordString=



;




String userString=



;




connection=DriverManager.


getConnection


(urlString,userSt ring,passwordS


tring);




return


connection;




}



解释:获取一个数据源,用于连接数据库。


< br>2.


利用传入的


sql


语句查找




public


ArrayList objectSelect(String sql)


throws


Exception{




ArrayList result=


new


ArrayList();




Connection connection=


null


;




Statement statement=


null


;




ResultSet resultSet=


null


;




try


{





connection=getConnection();





statement=Statement();





resultSet=eQuery(sql);





while


(())





{






student stu=


new


student();






((



));






o(ing(



));






me(ing(



));






x(ing(



));






anage((



));






inTimes((



));






inLastTime(ing(



));






sword((



));






e((



));











(stu);





}




}


catch


(SQLException e) {





throw



new


SQLException(



+sage());




}


catch


(Exception exception){





throw



new


Exception(



exception:


+sage());




}


finally


{





try


{






if


(r esultSet!=


null


){







();






}





}


catch


(Exception e){






throw



new


Exception(



exception:


+sage());





}





try


{






if


(connection!=


null


){







();






}





}


catch


(Exception e){






throw



new


Exception(



exception:


+sage());





}




}




return


result;



}


3.


向数据库中插入数据




public



void


insert(student student)


throws


Exception{




Connection connection=


null


;




PreparedStatement pStatement=


null


;




String sql=


< p>
student(ssno,sname,ssex,isManage,password,sa ge)


values('


+o()+



+me()+



+


x()+



+anage()+



+sword()+



+


age()+



;




try


{





connection=getConnection();





pStatement=eStatement(sql);





e();




}


cat ch


(SQLException e){





throw



new


Exception(



+sage());




}


catch


(Exception e){





throw



new


Exception(



+sage());




}


finally


{





try


{






if


(p Statement!=


null


)






{


(); }





}


catch


(Exception exception){






throw



new


Exception(





+sage());





}




}




try


{





if< /p>


(connection!=


null


)






();




}


catch


( Exception e) {





//


TODO


: handle exception






throw



new


Exception(



exception:


+sage());




}



}



//


通过传入的

student


对象删除表中的数据




public



void


delete(student student)


throws


Exception{




Connection connection=


null


;




PreparedStatement pStatement=


null


;




String sql=


< p>
+()+



;




try


{





connection=getConnection();





pStatement=eStatement(sql);





e();




}


catch


(SQLException e) {





//


TODO


: handle exception






throw



new


Exception(



+sage());




}


catch


(Exception e){





throw



new


Exception(



+sage());




}


finally


{





try


{






if


(p Statement!=


null


)






{


(); }





}


catch


(Exception exception){






throw



new


Exception(





+sage());





}




}




try


{





if< /p>


(connection!=


null


)






();




}


catch


( Exception e) {





//


TODO


: handle exception






throw



new


Exception(



exception:


+sage());




}



}


4.


修改数据库中的数据




public



void


update(student student)


throws


Exception{




Connection connection=


null


;




PreparedStatement pStatement=


null


;




String sql=


< p>
ssno=


+o()+



+ me()+



+student


.get Ssex()+



+







+anage()+



+sword()+



+









+e()+



+in Times()+




+











+inLastTime()+


< p>
sid=


+()+



;




try


{





connection=getConnection();





pStatement=eStatement(sql);





e();




}


catch


(SQLException e) {





//


TODO


: handle exception






throw



new


Exception(



+sage());


-


-


-


-


-


-


-


-



本文更新与2021-02-15 14:37,由作者提供,不代表本网站立场,转载请注明出处:https://www.bjmy2z.cn/gaokao/655476.html

南昌航空大学实验报告2-JavaBean和Servlet完成增删改查的相关文章

  • 爱心与尊严的高中作文题库

    1.关于爱心和尊严的作文八百字 我们不必怀疑富翁的捐助,毕竟普施爱心,善莫大焉,它是一 种美;我们也不必指责苛求受捐者的冷漠的拒绝,因为人总是有尊 严的,这也是一种美。

    小学作文
  • 爱心与尊严高中作文题库

    1.关于爱心和尊严的作文八百字 我们不必怀疑富翁的捐助,毕竟普施爱心,善莫大焉,它是一 种美;我们也不必指责苛求受捐者的冷漠的拒绝,因为人总是有尊 严的,这也是一种美。

    小学作文
  • 爱心与尊重的作文题库

    1.作文关爱与尊重议论文 如果说没有爱就没有教育的话,那么离开了尊重同样也谈不上教育。 因为每一位孩子都渴望得到他人的尊重,尤其是教师的尊重。可是在现实生活中,不时会有

    小学作文
  • 爱心责任100字作文题库

    1.有关爱心,坚持,责任的作文题库各三个 一则150字左右 (要事例) “胜不骄,败不馁”这句话我常听外婆说起。 这句名言的意思是说胜利了抄不骄傲,失败了不气馁。我真正体会到它

    小学作文
  • 爱心责任心的作文题库

    1.有关爱心,坚持,责任的作文题库各三个 一则150字左右 (要事例) “胜不骄,败不馁”这句话我常听外婆说起。 这句名言的意思是说胜利了抄不骄傲,失败了不气馁。我真正体会到它

    小学作文
  • 爱心责任作文题库

    1.有关爱心,坚持,责任的作文题库各三个 一则150字左右 (要事例) “胜不骄,败不馁”这句话我常听外婆说起。 这句名言的意思是说胜利了抄不骄傲,失败了不气馁。我真正体会到它

    小学作文
南昌航空大学实验报告2-JavaBean和Servlet完成增删改查随机文章