?? dbo.java
字號:
}
return 0;
}
//查詢某圖書所屬分類的最大借閱天數,由類BorrowBook調用
public static int selectKeepDaysofBook(int id){
String sql="select days from tb_bookType where id="+id;
ResultSet rs=Dbo.executeQuery(sql);
try{
if(rs.next()){
return rs.getInt("days");
}
else return 0;
}catch(Exception e){
e.printStackTrace();
return 0;
}
}
//為禁止管理員重復添加讀者借書信息的方法而設計的查詢方法,由類BorrowBook調用
public static int selectHasBorrowed(String readerId,String ISBN){
String sql="select * from tb_borrow where readerid='"+readerId+"' AND bookISBN='"+ISBN+"'";
ResultSet rs=Dbo.executeQuery(sql);
try{
if(rs.next()){
return 1;
}
else return 0;
}catch(Exception e){
e.printStackTrace();
return 1;
}
}
//查詢指定圖書類別的詳細信息,由類MoifyAndDelBook調用
public static BookType selectDetailBookType(String typeName){
String sql="select * from tb_bookType where typeName='"+typeName+"'";
ResultSet rs=Dbo.executeQuery(sql);
try{
BookType bookType=new BookType();
if(rs.next()){
bookType.setTypeName(rs.getString("typeName"));
bookType.setFk(rs.getInt("fk"));
bookType.setExpired(rs.getInt("expire"));
bookType.setDays(rs.getInt("days"));
bookType.setId(rs.getInt("id"));
return bookType;
}
}catch(Exception e){
e.printStackTrace();
return null;
}
return null;
}
//查詢所有圖書類別的信息,用于顯示所有圖書類別信息,由雷ModifyAndDelBook調用
public static ArrayList selectAllBookType(){
String sql="select * from tb_bookType";
ResultSet rs=Dbo.executeQuery(sql);
ArrayList arrayList=new ArrayList();
try{
while(rs.next()){
BookType bookType=new BookType();
bookType.setDays(rs.getInt("days"));
bookType.setExpired(rs.getInt("expire"));
bookType.setFk(rs.getInt("fk"));
bookType.setId(rs.getInt("id"));
bookType.setTypeName(rs.getString("typeName"));
arrayList.add(bookType);
}
Dbo.close();
return arrayList;
}catch(Exception e){
e.printStackTrace();
return null;
}
}
//查詢指定ID的讀者類型的方法,由類ModifyAndDelReader
public static ReaderType selectSelectedReaderType(int id){
String sql="select * from tb_readerType where typeId="+id;
ResultSet rs=Dbo.executeQuery(sql);
try{
if(rs.next()){
ReaderType readerType=new ReaderType();
readerType.setMaxBorrowNumber(rs.getInt("maxBorrowNumber"));
readerType.setmaxKeepDays(rs.getInt("maxKeepDays"));
readerType.setTypeId(id);
readerType.setTypeName(rs.getString("typeName"));
Dbo.close();
return readerType;
}
}catch(Exception e){
e.printStackTrace();
return null;
}
return null;
}
//按照指定的讀者類型名稱查詢讀者類型,由類ModifyAndDelReaderType
public static ReaderType selectDetailReaderType(String typeName){
String sql="select * from tb_readerType where typeName='"+typeName+"'";
ResultSet rs=Dbo.executeQuery(sql);
try{
if(rs.next()){
ReaderType readerType=new ReaderType();
readerType.setTypeName(typeName);
readerType.setTypeId(rs.getInt("typeId"));
readerType.setMaxBorrowNumber(rs.getInt("maxBorrowNumber"));
readerType.setmaxKeepDays(rs.getInt("maxKeepDays"));
return readerType;
}
}catch(Exception e){
e.printStackTrace();
return null;
}
return null;
}
//查詢所有圖書管理員,有類ModiftDelUser調用
public static ArrayList selectAllBookAdmin(){
String sql="select * from tb_operator where admin=0";
ResultSet rs=Dbo.executeQuery(sql);
ArrayList arrayList=new ArrayList();
try{
while(rs.next()){
Operator operator=new Operator();
operator.setName(rs.getString("name"));
operator.setId(rs.getInt("operatorId"));
operator.setIdentityCardNumber(rs.getString("identityCard"));
operator.setSex(rs.getString("sex"));
operator.setTel(rs.getString("tel"));
operator.setWorkDate(rs.getString("workdate"));
operator.setPassword(rs.getString("password"));
arrayList.add(operator);
}
return arrayList;
}catch(Exception e){
e.printStackTrace();
return null;
}
}
//判斷是否要修改的管理員是否與現有管理員重名的方法,由類ModifyDelUser調用
public static String selectSpecifiedOperatorName(String name,int id){
String sql="select name from tb_operator where name='"+name+"' And operatorId!="+id;
ResultSet rs=Dbo.executeQuery(sql);
try {
if(rs.next())
return rs.getString("name");
} catch (SQLException e) {
e.printStackTrace();
return null;
}
return null;
}
//查詢某管理員密碼的方法,由類ModifyPassword調用
public static String selectAdminPassword(int id){
String sql="select password from tb_operator where operatorID="+id;
ResultSet rs=Dbo.executeQuery(sql);
try {
if(rs.next())
return rs.getString(1);
} catch (SQLException e) {
e.printStackTrace();
return null;
}
return null;
}
//按照圖書名稱查找相應圖書的方法,有類SearchBook調用
public static ArrayList selectSpecifiedBook(String name){
String sql="select * from tb_bookInfo where bookname like '%"+name+"%'";
ResultSet rs=Dbo.executeQuery(sql);
ArrayList arrayList=new ArrayList();
try {
while(rs.next()){
Book book=new Book();
book.setBookname(rs.getString("bookname"));
book.setDate(rs.getString("date"));
book.setISBN(rs.getString("ISBN"));
book.setPrice(rs.getFloat("price"));
book.setPublisher(rs.getString("publisher"));
book.setTranslator(rs.getString("translator"));
book.setWriter(rs.getString("writer"));
arrayList.add(book);
}
return arrayList;
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}
//按照圖書作者查找相應圖書的方法,有類SearchBook調用
public static ArrayList selectSpecifiedWriterBook(String writer){
String sql="select * from tb_bookInfo where writer like '%"+writer+"%'";
ResultSet rs=Dbo.executeQuery(sql);
ArrayList arrayList=new ArrayList();
try {
while(rs.next()){
Book book=new Book();
book.setBookname(rs.getString("bookname"));
book.setDate(rs.getString("date"));
book.setISBN(rs.getString("ISBN"));
book.setPrice(rs.getFloat("price"));
book.setPublisher(rs.getString("publisher"));
book.setTranslator(rs.getString("translator"));
book.setWriter(rs.getString("writer"));
arrayList.add(book);
}
return arrayList;
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}
//查詢指定圖書編號的圖書信息,由類SearchBook調用
public static Book selectSpecifiedISBNBook(String ISBN){
String sql="select * from tb_bookinfo where ISBN='"+ISBN+"'";
ResultSet rs=Dbo.executeQuery(sql);
try {
if(rs.next()){
Book book=new Book();
book.setBookname(rs.getString("bookname"));
book.setDate(rs.getString("date"));
book.setISBN(rs.getString("ISBN"));
book.setPrice(rs.getFloat("price"));
book.setPublisher(rs.getString("publisher"));
book.setTranslator(rs.getString("translator"));
book.setWriter(rs.getString("writer"));
return book;
}
} catch (SQLException e) {
e.printStackTrace();
return null;
}
return null;
}
//顯示所有圖書信息,由類SearchBook調用
public static ArrayList selectAllBook(){
String sql="select * from tb_bookinfo";
ResultSet rs=Dbo.executeQuery(sql);
ArrayList arrayList =new ArrayList();
try {
while(rs.next()){
Book book=new Book();
book.setBookname(rs.getString("bookname"));
book.setDate(rs.getString("date"));
book.setISBN(rs.getString("ISBN"));
book.setPrice(rs.getFloat("price"));
book.setPublisher(rs.getString("publisher"));
book.setTranslator(rs.getString("translator"));
book.setWriter(rs.getString("writer"));
arrayList.add(book);
}
return arrayList;
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}
//查找某讀者所借圖書的所有信息,由類ReturnBook調用
public static ArrayList selectAllBorrowBook(String readerId){
String sql="select * from tb_borrow where readerid='"+readerId+"'";
ResultSet rs=Dbo.executeQuery(sql);
ArrayList arrayList=new ArrayList();
try {
while(rs.next()){
BorrowBookEntity borrowBookEntity=new BorrowBookEntity();
borrowBookEntity.setBackDate(rs.getString("backDate"));
borrowBookEntity.setBorrowDate(rs.getString("borrowDate"));
borrowBookEntity.setISBN(rs.getString("bookISBN"));
borrowBookEntity.setOperatorId(rs.getInt("operatorID"));
borrowBookEntity.setReaderId(rs.getString("readerid"));
arrayList.add(borrowBookEntity);
}
return arrayList;
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}
//查詢指定讀者編號和指定書號的借閱信息由類ReturnBook調用
public static BorrowBookEntity selectSpecifiedBorrowInfo(String readerId,String ISBN){
String sql="select * from tb_borrow where readerid='"+readerId+"' and bookISBN='"+ISBN+"'";
ResultSet rs=Dbo.executeQuery(sql);
try {
if(rs.next()){
BorrowBookEntity borrowBookEntity=new BorrowBookEntity();
borrowBookEntity.setBackDate(rs.getString("backDate"));
borrowBookEntity.setBorrowDate(rs.getString("borrowDate"));
borrowBookEntity.setISBN(rs.getString("bookISBN"));
borrowBookEntity.setOperatorId(rs.getInt("operatorID"));
borrowBookEntity.setReaderId(rs.getString("readerid"));
return borrowBookEntity;
}
} catch (SQLException e) {
e.printStackTrace();
return null;
}
return null;
}
//查詢指定書號是否已經在定書表中出現,由類OrdernewBook調用
public static String selectNewBookISBN(String ISBN){
String sql="select * from tb_order where ISBN='"+ISBN+"'";
ResultSet rs=Dbo.executeQuery(sql);
try {
if(rs.next()){
return rs.getString("ISBN");
}
} catch (SQLException e) {
e.printStackTrace();
return null;
}
return null;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -