📄 book.java
字号:
package dbBean;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
public class book
{
public ResultSet bookSearch(int type,int extra,String input)
{
String sql = null;
if(extra==0)
{
if(type==2)
{
sql="select * from Book where Book_name='"+input+"'";
}
if(type==3)
{
sql="select * from Book where author='"+input+"'";
}
if(type==4)
{
sql="select * from Book where Translator='"+input+"'";
}
if(type==5)
{
sql="select * from Book where Publish_house='"+input+"'";
}
if(type==6)
{
sql="select * from Book where Congshu_name='"+input+"'";
}
if(type==7)
{
sql="select * from Book where Lost_page_num >0";
}
}
else
{
sql="select * from Book where Book_type_ID="+extra;
}
dbConnection dbConn=new dbConnection();
dbConn.getConnect("bookshop", "manager", "123");
ResultSet rs=dbConn.selectSql(sql);
return rs;
}
public int addBook(String name,String isbn,String author,String Congshu_name,String Translator,String Publish_house,int Storage_num,String provider,int Book_type_ID)//,String price)
{
ResultSet rs;
boolean tell=false;
dbConnection dbConn=new dbConnection();
dbConn.getConnect("bookshop", "manager", "123");
try {
String sql="select * from Book where ISBN="+isbn;
System.out.println(sql);
ResultSet test=dbConn.selectSql(sql);
if(test.next())
{
String bookname=test.getString("Book_name");
String bookid=test.getString("Book_ID");
String bookauthor=test.getString("author");
int typeid=Integer.parseInt(test.getString("Book_type_ID"));
/**if(bookname!=null||(!bookname.equals(name)))
{
String aa=rstest.getString("Book_name");
System.out.println(aa);
return 1;
}
if(rstest.getString("Book_ID")!=null||rstest.getString("Book_ID")!=name)
{
return 2;
}
if(rstest.getString("author")!=null||rstest.getString("author")!=name)
{
return 3;
}
if(rstest.getString("Book_type_ID")!=null||rstest.getString("Book_type_ID")!=name)
{
return 4;
}
**/
String booknum=test.getString("Storage_num");
int bookNum;
if(booknum==null)
{
bookNum=0;
}
else
bookNum=Integer.parseInt(booknum);
bookNum=bookNum+Storage_num;
sql="update Book set Storage_num="+bookNum+" where ISBN='"+isbn+"'";
tell=dbConn.deleteSql(sql);
if(tell==true)
return 11;
else
return 0;
}
else
{
String sqlBook="select max(Book_ID) from Book";
int Bookid=0;
rs=dbConn.selectSql(sqlBook);
if(rs.next())
{
String book_id=rs.getString(1);
if(book_id==null)
{
Bookid=-1;
}
else
Bookid=Integer.parseInt(book_id);
}
Bookid=Bookid+1;
provider aa=new provider();
int salemanid=aa.insertProvider(provider);
Date date = new Date(System.currentTimeMillis());
String time=date.toString();
sql="insert into Book(Book_name,Book_ID,ISBN,author,Congshu_name,Translator,Publish_house,Storage_num,Book_type_ID,Salesman_ID,Times) values ('"+name+"',"+Bookid+",'"+isbn+"',"+"'"+author+"',"+"'"+Congshu_name+"',"+"'"+Translator+"',"+"'"+Publish_house+"',"+Storage_num+","+Book_type_ID+","+salemanid+",'"+time+"')";
tell=dbConn.deleteSql(sql);
if(tell==true)
return 11;
else
return 0;
}
}
catch (SQLException e)
{
e.printStackTrace();
return 0;
}
}
public boolean delete(String isbn) throws SQLException
{
String sql="select * from Book where ISBN='"+isbn+"'";
System.out.println(sql);
dbConnection dbConn=new dbConnection();
boolean tell;
dbConn.getConnect("bookshop", "manager", "123");
ResultSet rstest=dbConn.selectSql(sql);
if(rstest.next())
{
String bookNum=rstest.getString("Storage_num");
if(bookNum==null)
tell=true;
else
sql="delete from Book where ISBN='"+isbn+"'";
tell=dbConn.deleteSql(sql);
}
else
{
tell=false;
}
return tell;
}
public boolean typeUpdate(String isbn,String type)
{
String sql="update Book set Book_type_ID="+Integer.parseInt(type)+" where ISBN='"+isbn+"'";
System.out.println(sql);
dbConnection dbConn=new dbConnection();
boolean tell;
dbConn.getConnect("bookshop", "manager", "123");
tell=dbConn.deleteSql(sql);
return tell;
}
public boolean update(String isbn,String num)
{
String sql="update Book set Storage_num=Storage_num+"+Integer.parseInt(num)+" where ISBN='"+isbn+"'";
System.out.println(sql);
dbConnection dbConn=new dbConnection();
boolean tell;
dbConn.getConnect("bookshop", "manager", "123");
tell=dbConn.deleteSql(sql);
return tell;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -