欢迎来到天天文库
浏览记录
ID:37846324
大小:192.50 KB
页数:17页
时间:2019-06-01
《JSP_网上搜集的分页及example搜索相关代码》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、JSP分页查询关键代码1.连接数据库的基类:packagecom.book.commons;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.PreparedStatement;importjava.sql.ResultSet;importjava.sql.SQLException;publicclassGetConnection{protectedConnectionconn=null;//连接字符串protectedPrepared
2、Statementps=null;//预编译并存储SQL指令protectedResultSetrs=null;//查询结果集privatestaticfinalStringDRIVER="com.microsoft.sqlserver.jdbc.SQLServerDriver";//加载数据库驱动的字符串privatestaticfinalStringURL="jdbc:sqlserver://localhost:1433;databaseName=BOOKDB";//连接数据库的字符串privatestaticfinal
3、StringUSERNAME="sa";//数据库用户名privatestaticfinalStringPASSWORD="accp";//数据库用户密码/***获得数据库连接*@return*/publicConnectiongetConn(){Connectionconn=null;try{Class.forName(DRIVER);//加载数据库驱动conn=DriverManager.getConnection(URL,USERNAME,PASSWORD);//连接数据库}catch(ClassNotFoundExc
4、eptione){//TODOAuto-generatedcatchblocke.printStackTrace();}catch(SQLExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}returnconn;}/**释放资源*/publicvoidcloseAll(){try{if(rs!=null){rs.close();}if(ps!=null){ps.close();}if(conn!=null){conn.close();}}catch(S
5、QLExceptione){e.printStackTrace();}finally{conn=null;ps=null;rs=null;}}}1.实体类代码:packagecom.book.entity;publicclassBook{privateintbook_id;privateStringbook_name;privateStringbook_num;privateStringbook_author;privatedoublebook_price;privateStringbook_synopsis;private
6、Stringbook_publishTime;publicStringgetBook_author(){returnbook_author;}publicvoidsetBook_author(Stringbook_author){this.book_author=book_author;}publicintgetBook_id(){returnbook_id;}publicvoidsetBook_id(intbook_id){this.book_id=book_id;}publicStringgetBook_name(){r
7、eturnbook_name;}publicvoidsetBook_name(Stringbook_name){this.book_name=book_name;}publicStringgetBook_num(){returnbook_num;}publicvoidsetBook_num(Stringbook_num){this.book_num=book_num;}publicdoublegetBook_price(){returnbook_price;}publicvoidsetBook_price(doubleboo
8、k_price){this.book_price=book_price;}publicStringgetBook_publishTime(){returnbook_publishTime;}publicvoidsetBook_publishTime(Stringbook_publishTi
此文档下载收益归作者所有