?? op_book.java
字號:
sqlStr = sqlStr + " and (upper(a.bookname) like '%" +
keyword+ "%' or upper(a.content) like '%" +
keyword + "%') order by a.Id desc";
}
} else {
if (!classid.equals("")){
sqlStr = sqlStr + " and a.Bookclass='" + classid + "'"+
" and (upper(a.bookname) like '%" + keyword + "%'"+
" or upper(a.content) like '%" + keyword + "%')";
} else {
sqlStr = sqlStr + " and (upper(a.bookname) like '%" +keyword+ "%'"+
" or upper(a.content) like '%" +keyword + "%')";
}
}
} else {//非查詢,也非分類瀏覽
if (page == 1){
sqlStr = sqlStr + " order by a.Id desc";
} else {
sqlStr = sqlStr;
}
}
try {
rs = stmt.executeQuery(sqlStr);
booklist = new Vector(rscount);
while (rs.next()){
book book = new book();
book.setId(rs.getLong("id"));
book.setBookName(rs.getString("bookname"));
book.setBookClass(rs.getInt("bookclass"));
book.setClassname(rs.getString("classname"));
book.setAuthor(rs.getString("author"));
book.setPublish(rs.getString("publish"));
book.setBookNo(rs.getString("Bookno"));
book.setContent(rs.getString("content"));
book.setPrince(rs.getFloat("prince"));
book.setAmount(rs.getInt("amount"));
book.setLeav_number(rs.getInt("leav_number"));
book.setRegTime(rs.getString("regtime"));
book.setPicture(rs.getString("picture"));
booklist.addElement(book);
}
rs.close();
return true;
}catch (Exception e){
System.out.println(e.getMessage());
return false;
}
}
/**
* 完成圖書添加
* @return
* @throws java.lang.Exception
*/
public boolean insert() throws Exception {
sqlStr = "insert into book (Bookname,Bookclass,Author,Publish,Bookno,"+
"Content,Prince,Amount,Leav_number,Regtime,picture) values ('";
sqlStr = sqlStr + dataFormat.toSql(abooks.getBookName()) + "','";
sqlStr = sqlStr + abooks.getBookClass() + "','";
sqlStr = sqlStr + dataFormat.toSql(abooks.getAuthor()) + "','";
sqlStr = sqlStr + dataFormat.toSql(abooks.getPublish()) + "','";
sqlStr = sqlStr + dataFormat.toSql(abooks.getBookNo()) + "','";
sqlStr = sqlStr + dataFormat.toSql(abooks.getContent()) + "','";
sqlStr = sqlStr + abooks.getPrince() + "','";
sqlStr = sqlStr + abooks.getAmount() + "','";
sqlStr = sqlStr + abooks.getAmount() + "',";
sqlStr = sqlStr + "now()"+ ",'";
sqlStr = sqlStr + abooks.getPicture()+"')";
try{
System.out.print(sqlStr);
DataBase db = new DataBase();
Connection conn=db.connect();
stmt =conn.createStatement ();
stmt.execute(sqlStr);
return true;
}catch (SQLException sqle){
System.out.print(sqle.getMessage());
return false;
}
}
/**
* 完成圖書修改
* @return
* @throws java.lang.Exception
*/
public boolean update() throws Exception {
sqlStr = "update book set ";
sqlStr = sqlStr + "bookname = '" + dataFormat.toSql(abooks.getBookName()) + "',";
sqlStr = sqlStr + "bookclass = '" + abooks.getBookClass() + "',";
sqlStr = sqlStr + "Author = '" + dataFormat.toSql(abooks.getAuthor()) + "',";
sqlStr = sqlStr + "publish = '" + dataFormat.toSql(abooks.getPublish()) + "',";
sqlStr = sqlStr + "bookno = '" + dataFormat.toSql(abooks.getBookNo()) + "',";
sqlStr = sqlStr + "content = '" + dataFormat.toSql(abooks.getContent()) + "',";
sqlStr = sqlStr + "prince = '" + abooks.getPrince() + "',";
sqlStr = sqlStr + "Amount = '" + abooks.getAmount() + "',";
sqlStr = sqlStr + "leav_number = '" + abooks.getLeav_number()+ "' ,";
sqlStr = sqlStr + "picture = '" + abooks.getPicture() + "' ";
sqlStr = sqlStr + "where id = " + abooks.getId();
try{
DataBase db = new DataBase();
db.connect();
stmt =db.conn.createStatement ();
stmt.execute(sqlStr);
return true;
} catch (SQLException e){
System.out.print(e.getMessage());
return false;
}
}
/**
* 完成圖書刪除
* @param aid
* @return
* @throws java.lang.Exception
*/
public boolean delete( int aid ) throws Exception {
sqlStr = "delete from book where id = " + aid ;
try
{ DataBase db = new DataBase();
Connection conn=db.connect();
stmt =conn.createStatement ();
stmt.execute(sqlStr);
return true;
}
catch (SQLException e)
{
System.out.println(e);
return false;
}
}
/**
* 完成圖書單本查詢,用于支持頁面的查看圖書詳細資料
* @param newid
* @return
* @throws java.lang.Exception
*/
public boolean getOnebook(int newid ) throws Exception {
DataBase db = new DataBase();
Connection conn=db.connect();
stmt =conn.createStatement ();
try {
sqlStr="select a.id,a.bookname,a.bookclass,b.classname,a.author,"+
"a.publish,a.bookno,a.content,a.prince,a.amount,a.Leav_number,"+
"a.regtime,a.picture from book a,bookclass b where a.Bookclass="+
"b.Id and a.Id = " + newid ;
rs = stmt.executeQuery(sqlStr);
if (rs.next())
{ booklist = new Vector(1);
book book = new book();
book.setId(rs.getLong("id"));
book.setBookName(rs.getString("bookname"));
book.setBookClass(rs.getInt("bookclass"));
book.setClassname(rs.getString("classname"));
book.setAuthor(rs.getString("author"));
book.setPublish(rs.getString("publish"));
book.setBookNo(rs.getString("Bookno"));
book.setContent(rs.getString("content"));
book.setPrince(rs.getFloat("prince"));
book.setAmount(rs.getInt("amount"));
book.setLeav_number(rs.getInt("leav_number"));
book.setRegTime(rs.getString("regtime"));
book.setPicture(rs.getString("picture"));
booklist.addElement(book);
} else {
rs.close();
return false;
}
rs.close();
return true;
}
catch (SQLException e)
{
return false;
}
}
public int getPage() { //顯示的頁碼
return page;
}
public void setPage(int newpage) {
page = newpage;
}
public int getPageSize(){ //每頁顯示的圖書數
return pageSize;
}
public void setPageSize(int newpsize) {
pageSize = newpsize;
}
public int getPageCount() { //頁面總數
return pageCount;
}
public void setPageCount(int newpcount) {
pageCount = newpcount;
}
public long getRecordCount() {
return recordCount;
}
public void setRecordCount(long newrcount) {
recordCount= newrcount;
}
public op_book() {
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -