📄 simplesearch.java
字号:
package web;
import lms.*;
import java.util.Vector;
import java.sql.SQLException;
/**
* 简单查询操作: 分别通过单一条件来查询书目
* BookIndex
* ISBN
* Writer
* Press
* KeyWords
* BookName
*/
public class SimpleSearch
extends DataBase {
//Book book = new Book();
public SimpleSearch() {
super();
}
public Vector SimpleSearchByISBN(String ISBN)
{
Vector v=new Vector();
/*
this.sqlstr = "select Book.BookIndex,Book.ISBN,Book.State,"
+"BookInf.BookName,BookInf.Writer,BookInf.Press,BookInf.Amount,"
+"BookInf.Summary,BookInf.Type,BookInf.Price,BookInf.PublishDay,"
+"BookInf.Shelf,BookInf.ReservationAmount from Book,BookInf where Book.ISBN=BookInf.ISBN and ";
*/
this.sqlstr = "select BookName,Press,Amount,Summary,PublishDay,ReservationAmount from BookInf "
+"where ISBN='"+ISBN+"'";
//this.sqlstr += "Book.ISBN='"+ISBN+"'";
try
{
//System.out.println(sqlstr);
rs = stm.executeQuery(sqlstr);
while (rs.next())
{
Book book = new Book();
//book.setBookIndex(rs.getString("BookIndex"));
book.setBookName(rs.getString("BookName"));
//System.out.println("a");
book.setPress(rs.getString("Press"));
//System.out.println("C");
// System.out.println(rs.getString("PublishDay").toString());
book.setAmount(rs.getInt("Amount"));
//System.out.println("E");
book.setSummary(rs.getString("Summary"));
//System.out.println("F");
book.setPublishDay(rs.getString("PublishDay").substring(0,10));
//System.out.println("D");
book.setReservationAmount(rs.getInt("ReservationAmount"));
//book.setWriter(rs.getString("Writer"));
//System.out.println(rs.getString("Writer"));
v.addElement(book);
//System.out.println("a");
}
}catch(Exception e)
{
System.out.println("ISBN Exception");
System.out.println(e.getMessage());
}
return v;
}
public Vector SimpleSearchByWriter(String Writer)
{
Vector v = new Vector();
/*
this.sqlstr = "select Book.BookIndex,Book.ISBN,Book.State,"
+"BookInf.BookName,BookInf.Writer,BookInf.Press,BookInf.Amount,"
+"BookInf.Summary,BookInf.Type,BookInf.Price,BookInf.PublishDay,"
+"BookInf.Shelf,BookInf.ReservationAmount from Book,BookInf where Book.ISBN=BookInf.ISBN and ";
this.sqlstr += "BookInf.Writer='"+Writer+"'";
*/
sqlstr = "select BookName,Press,Amount,Summary,PublishDay,ReservationAmount from BookInf "
+"where Writer like '"+"%"+Writer+"%"+"'";
try
{
//System.out.println(sqlstr);
rs = stm.executeQuery(sqlstr);
while (rs.next())
{
Book book = new Book();
//book.setBookIndex(rs.getString("BookIndex"));
book.setBookName(rs.getString("BookName"));
//System.out.println("a");
book.setPress(rs.getString("Press"));
//System.out.println("C");
// System.out.println(rs.getString("PublishDay").toString());
book.setAmount(rs.getInt("Amount"));
//System.out.println("E");
book.setSummary(rs.getString("Summary"));
//System.out.println("F");
book.setPublishDay(rs.getString("PublishDay").substring(0,10));
//System.out.println("D");
book.setReservationAmount(rs.getInt("ReservationAmount"));
//book.setWriter(rs.getString("Writer"));
//System.out.println(rs.getString("Writer"));
v.addElement(book);
//System.out.println("a");
}
}catch(SQLException e)
{
System.out.println("Writer Exception");
System.out.println(e.getMessage());
}
return v;
}
public String getISBN(String BookIndex)
{
String ISBN="";
String sql = "select ISBN from Book where BookIndex='"+BookIndex+"'";
try
{
//System.out.println(sql);
rs = stm.executeQuery(sql);
if(rs.absolute(1))
{
ISBN=rs.getString("ISBN");
}
//System.out.println("TEST---"+ISBN);
}
catch(Exception ex)
{
System.out.println(ex.getMessage());
}
return ISBN;
}
public Vector SimpleSearchByBookIndex(String BookIndex)
{
Vector v = new Vector();
String ISBN=this.getISBN(BookIndex);
sqlstr = "select BookName,Press,Amount,Summary,PublishDay,ReservationAmount from BookInf "
+"where BookIndex='"+BookIndex+"'";
try
{
//System.out.println(sqlstr);
rs = stm.executeQuery(sqlstr);
while (rs.next())
{
Book book = new Book();
//book.setBookIndex(rs.getString("BookIndex"));
book.setBookName(rs.getString("BookName"));
//System.out.println("a");
book.setPress(rs.getString("Press"));
//System.out.println("C");
// System.out.println(rs.getString("PublishDay").toString());
book.setAmount(rs.getInt("Amount"));
//System.out.println("E");
book.setSummary(rs.getString("Summary"));
//System.out.println("F");
book.setPublishDay(rs.getString("PublishDay").substring(0,10));
//System.out.println("D");
book.setReservationAmount(rs.getInt("ReservationAmount"));
//book.setWriter(rs.getString("Writer"));
//System.out.println(rs.getString("Writer"));
v.addElement(book);
//System.out.println("a");
}
}catch(SQLException e)
{
System.out.println("BookIndex Exception");
System.out.println(e.getMessage());
}
return v;
}
public Vector SimpleSearchByPress(String Press)// throws SQLException
{
Vector v = new Vector();
sqlstr = "select BookName,Press,Amount,Summary,PublishDay,ReservationAmount from BookInf "
+"where Press like '"+Press+"%"+"'";
try
{
//System.out.println(sqlstr);
rs = stm.executeQuery(sqlstr);
while (rs.next())
{
Book book = new Book();
//book.setBookIndex(rs.getString("BookIndex"));
book.setBookName(rs.getString("BookName"));
//System.out.println("a");
book.setPress(rs.getString("Press"));
//System.out.println("C");
// System.out.println(rs.getString("PublishDay").toString());
book.setAmount(rs.getInt("Amount"));
//System.out.println("E");
book.setSummary(rs.getString("Summary"));
//System.out.println("F");
book.setPublishDay(rs.getString("PublishDay").substring(0,10));
//System.out.println("D");
book.setReservationAmount(rs.getInt("ReservationAmount"));
//book.setWriter(rs.getString("Writer"));
//System.out.println(rs.getString("Writer"));
v.addElement(book);
//System.out.println("a");
}
}catch(SQLException e)
{
System.out.println("Press Exception");
System.out.println(e.getMessage());
}
return v;
}
public Vector SimpleSearchByBookName(String BookName)
{
Vector v = new Vector();
sqlstr = "select BookName,Press,Amount,Summary,PublishDay,ReservationAmount from BookInf "
+"where BookName like '"+"%"+BookName+"%"+"'";
try
{
//System.out.println(sqlstr);
rs = stm.executeQuery(sqlstr);
while (rs.next())
{
Book book = new Book();
//book.setBookIndex(rs.getString("BookIndex"));
book.setBookName(rs.getString("BookName"));
//System.out.println("a");
book.setPress(rs.getString("Press"));
//System.out.println("C");
// System.out.println(rs.getString("PublishDay").toString());
book.setAmount(rs.getInt("Amount"));
//System.out.println("E");
book.setSummary(rs.getString("Summary"));
//System.out.println("F");
book.setPublishDay(rs.getString("PublishDay").substring(0,10));
//System.out.println("D");
book.setReservationAmount(rs.getInt("ReservationAmount"));
//book.setWriter(rs.getString("Writer"));
//System.out.println(rs.getString("Writer"));
v.addElement(book);
//System.out.println("a");
}
}
catch(SQLException e)
{
System.out.println("BookName Exception");
System.out.println(e.getMessage());
}
return v;
}
public Vector SimpleSearchBySummary(String Summary)
{
Vector v = new Vector();
sqlstr = "select BookName,Press,Amount,Summary,PublishDay,ReservationAmount from BookInf "
+"where Summary like '"+"%"+Summary+"%"+"'";
try
{
System.out.println(sqlstr);
rs = stm.executeQuery(sqlstr);
while (rs.next())
{
Book book = new Book();
//book.setBookIndex(rs.getString("BookIndex"));
book.setBookName(rs.getString("BookName"));
//System.out.println("a");
book.setPress(rs.getString("Press"));
//System.out.println("C");
// System.out.println(rs.getString("PublishDay").toString());
book.setAmount(rs.getInt("Amount"));
//System.out.println("E");
book.setSummary(rs.getString("Summary"));
//System.out.println("F");
book.setPublishDay(rs.getString("PublishDay").substring(0,10));
//System.out.println("D");
book.setReservationAmount(rs.getInt("ReservationAmount"));
//book.setWriter(rs.getString("Writer"));
//System.out.println(rs.getString("Writer"));
v.addElement(book);
//System.out.println("a");
}
}
catch(SQLException e)
{
System.out.println("BookName Exception");
System.out.println(e.getMessage());
}
return v;
}
/*test*/
public static void main(String[] args)
{
SimpleSearch ss = new SimpleSearch();
Vector v=ss.SimpleSearchByWriter("皆");
System.out.println(((Book)v.elementAt(0)).getAmount());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -