📄 bsbookinfo.java
字号:
String sql = "";
sql = "delete from book_info where id = '"+id+"' ";
dbconn.execute(sql);
}
/**
* 根据不同的查询条件列出图书信息
* @param userId
* @param selectkey
* @param selectm
* @return Vector
* @throws SQLException
* @throws IOException
*/
public Vector getBookByCondition(String userId,
String selectkey,
String selectm)throws SQLException,IOException
{
Vector v = null;
String sql = "";
sql = "select * from book_info where userId='"+userId+"' ";
if(selectm.equals("bookname"))
sql = sql + " and bookName='"+selectkey+"' ";
if(selectm.equals("summary"))
sql = sql + " and summary like '%"+selectkey+"%' ";
if(selectm.equals("bookid"))
sql = sql + " and id='"+selectkey+"' ";
if(selectm.equals("1"))
sql = sql + " and type like '%1%'";
if(selectm.equals("2"))
sql = sql + " and type like '%2%'";
if(selectm.equals("3"))
sql = sql + " and type like '%3%'";
sql = sql + "order by createDate ";
System.out.println("sql"+sql);
v = dbconn.ListOfMapData(sql);
return v;
}
/**
* 根据不同的查询条件列出图书信息
* @param userId
* @param selectkey
* @param selectm
* @param begin 返回结果的开始点
* @param end 返回结果的结束点
* @return Vector
* @throws SQLException
* @throws IOException
*/
public Vector getBookByCondition(String userId,
String selectkey,
String selectm,int begin,int end)throws SQLException,IOException
{
Vector v = null;
String sql = "";
sql = "select * from book_info where userId='"+userId+"' ";
if(selectm.equals("bookname")&&selectkey!=null&&!"null".equals(selectkey))
sql = sql + " and bookName='"+selectkey+"' ";
if(selectm.equals("summary")&&selectkey!=null&&!"null".equals(selectkey))
sql = sql + " and summary like '%"+selectkey+"%' ";
if(selectm.equals("bookid")&&selectkey!=null&&!"null".equals(selectkey))
sql = sql + " and id='"+selectkey+"' ";
if(selectm.equals("type")&&selectkey!=null&&!"null".equals(selectkey))
sql = sql + " and type like '%"+selectkey+"%' ";
if(selectm.equals("classifyMidId")&&selectkey!=null&&!"null".equals(selectkey))
sql = sql + " and classifyMidId = '"+selectkey+"' ";
sql = sql + "order by createDate LIMIT "+begin+","+(end-begin);
System.out.println("sql"+sql);
v = dbconn.ListOfMapData(sql);
return v;
}
public Vector getBookByCondition(
String bigClassifyId,
String classifyMidId,String classifySmallId,String bookName,
String author,String publishId,String bookNumber,int begin,int end)throws SQLException,IOException
{
Vector v = null;
String sql = "";
boolean isFirst = true;
sql = "select * from book_info ";
String condition = "";
if(bigClassifyId!=null)
{
isFirst=false;
condition +=" classifyBigId = "+bigClassifyId+" ";
}
if(classifyMidId!=null)
{
if(!isFirst)
{
condition +=" and ";
}
isFirst=false;
condition +=" classifyMidId = "+classifyMidId+" ";
}
if(classifySmallId!=null)
{
if(!isFirst)
{
condition +=" and ";
}
isFirst=false;
condition +=" classifySmallId = "+classifySmallId+" ";
}
if(bookName!=null)
{
if(!isFirst)
{
condition +=" and ";
}
isFirst=false;
condition +=" bookName like '%"+bookName+"%' ";
}
if(author!=null)
{
if(!isFirst)
{
condition +=" and ";
}
isFirst=false;
condition +=" author like '%"+author+"%' ";
}
if(publishId!=null)
{
if(!isFirst)
{
condition +=" and ";
}
isFirst=false;
condition +=" publishId = "+publishId+" ";
}
if(bookNumber!=null)
{
if(!isFirst)
{
condition +=" and ";
}
isFirst=false;
condition +=" bookNumber like '%"+bookNumber+"%' ";
}
if(!"".equals(condition))
{
sql += " where "+condition;
}
sql = sql + "order by createDate LIMIT "+begin+","+(end-begin);
System.out.println("sql"+sql);
v = dbconn.ListOfMapData(sql);
return v;
}
public int getBookCountByCondition(
String bigClassifyId,
String classifyMidId,String classifySmallId,String bookName,
String author,String publishId,String bookNumber)throws SQLException,IOException
{
String sql = "";
boolean isFirst = true;
sql = "select count(*) from book_info ";
String condition = "";
if(bigClassifyId!=null)
{
isFirst=false;
condition +=" classifyBigId = "+bigClassifyId+" ";
}
if(classifyMidId!=null)
{
if(!isFirst)
{
condition +=" and ";
}
isFirst=false;
condition +=" classifyMidId = "+classifyMidId+" ";
}
if(classifySmallId!=null)
{
if(!isFirst)
{
condition +=" and ";
}
isFirst=false;
condition +=" classifySmallId = "+classifySmallId+" ";
}
if(bookName!=null)
{
if(!isFirst)
{
condition +=" and ";
}
isFirst=false;
condition +=" bookName like '%"+bookName+"%' ";
}
if(author!=null)
{
if(!isFirst)
{
condition +=" and ";
}
isFirst=false;
condition +=" author like '%"+author+"%' ";
}
if(publishId!=null)
{
if(!isFirst)
{
condition +=" and ";
}
isFirst=false;
condition +=" publishId = "+publishId+" ";
}
if(bookNumber!=null)
{
if(!isFirst)
{
condition +=" and ";
}
isFirst=false;
condition +=" bookNumber like '%"+bookNumber+"%' ";
}
if(!"".equals(condition))
{
sql += " where "+condition;
}
sql = sql + "order by createDate ";
System.out.println("sql"+sql);
ResultSet result = dbconn.executeQuery(sql);
if(result.next())
return result.getInt(1);
return 0;
}
/**
* 根据不同的查询条件列出图书信息
* @param userId
* @param selectkey
* @param selectm
* @param begin 返回结果的开始点
* @param end 返回结果的结束点
* @return Vector
* @throws SQLException
* @throws IOException
*/
public int getBookCountByCondition(String userId,
String selectkey,
String selectm)throws SQLException,IOException
{
String sql = "";
sql = "select count(*) from book_info where userId='"+userId+"' ";
if(selectm.equals("bookname")&&selectkey!=null&&!"null".equals(selectkey))
sql = sql + " and bookName='"+selectkey+"' ";
if(selectm.equals("summary")&&selectkey!=null&&!"null".equals(selectkey))
sql = sql + " and summary like '%"+selectkey+"%' ";
if(selectm.equals("bookid")&&selectkey!=null&&!"null".equals(selectkey))
sql = sql + " and id='"+selectkey+"' ";
if(selectm.equals("type")&&selectkey!=null&&!"null".equals(selectkey))
sql = sql + " and type like '%"+selectkey+"%' ";
if(selectm.equals("classifyMidId")&&selectkey!=null&&!"null".equals(selectkey))
sql = sql + " and classifyMidId = '"+selectkey+"' ";
System.out.println("sql"+sql);
ResultSet result = dbconn.executeQuery(sql);
if(result.next())
return result.getInt(1);
return 0;
}
/**
* 找出ID相对应的图书对象
* @param id
* @return Vector
* @throws SQLException
* @throws IOException
*/
public Vector getBookById(String id)throws SQLException,IOException
{
Vector v = null;
String sql = "";
sql = "select * from book_info where id='"+id+"' order by createDate ";
v = dbconn.ListOfMapData(sql);
return v;
}
/**
* 根据馆区名称找出相对应的图书大类的ID
* @param libraryName
* @return String
* @throws SQLException
* @throws IOException
*/
public String getClassifyBigIdByLibraryName(String libraryName)
throws SQLException,IOException
{
String bigId = "";
String bigName = "";
Vector v = getAllBookClassifyBig();
if(v!=null && v.size()>0)
{
for(int i=0;i<v.size();i++)
{
Map map = (Map)v.get(i);
bigName = (String)map.get("classifyName");
if(libraryName.substring(0,libraryName.length()-1).equals(bigName))
{
bigId = (String)map.get("id");
}
}
}
return bigId;
}
/**
* 根据馆区ID找到相应的图书列表
* @param libraryId
* @return Vector
* @throws SQLException
* @throws IOException
*/
public Vector getBookByLibraryId(String libraryId,String bookMidId)
throws SQLException,IOException
{
Vector v = null;
String sql = "";
sql = "select * from book_info where libraryId='"+libraryId+"' " ;
if(bookMidId.length()!=0)
sql = sql + "and classifyMidId='"+bookMidId+"' ";
sql = sql + "order by createDate desc";
v = dbconn.ListOfMapData(sql);
return v;
}
/**
* 添加图书评论
* @param bookId
* @param commentTitle
* @param commentContent
* @throws SQLException
* @throws IOException
*/
public void addBookComment(String bookId,
String commentTitle,
String commentContent) throws SQLException,IOException
{
String sql = "";
sql = "insert into book_comment(bookId,commentTitle,commentContent,createDate) " +
"VALUES('"+bookId+"','"+commentTitle+"','"+commentContent+"'," +
"'"+StringUtil.genDateTimeString()+"')";
System.out.println("sql = "+sql);
dbconn.execute(sql);
}
public Vector getBookComment(int begin,int end) throws SQLException,IOException
{
int count = end-begin;
String sql = "select * from book_comment order by createDate desc limit "+begin+" , "+count;
return dbconn.ListOfMapData(sql);
}
public Vector getBookCommentById(String bookId,int begin,int end) throws SQLException,IOException
{
int count = end-begin;
String sql = "select * from book_comment where bookId='"+bookId+"' order by createDate desc limit "+begin+" , "+count;
System.out.println("sql = "+sql);
return dbconn.ListOfMapData(sql);
}
public Vector getCommentById(String commentId) throws SQLException,IOException
{
String sql = "select * from book_comment where id='"+commentId+"' order by createDate desc ";
return dbconn.ListOfMapData(sql);
}
/**
* 根据ID找出最后一次书评的内容
* @param Id
* @return String
* @throws SQLException
* @throws IOException
*/
public String getBookCommentByBookId(String bookid)
throws SQLException,IOException
{
String commentContent = "";
Vector v = null;
String sql = "";
sql = "select * from book_comment where bookId='"+bookid+"' order by createDate desc ";
v = dbconn.ListOfMapData(sql);
if(v!=null && v.size()>0)
{
Map map = (Map)v.get(0);
commentContent = (String)map.get("commentContent");
}
return commentContent;
}
/**
* 列出所有的图书
*/
public Vector getBookInfo()throws SQLException,IOException
{
Vector v = null;
String sql = "";
sql = "select * from book_info order by createDate desc";
v = dbconn.ListOfMapData(sql);
return v;
}
/**
* 列出所有的评论
* @return Vector
* @throws SQLException
* @throws IOException
*/
public Vector getBookComment()throws SQLException,IOException
{
Vector v = null;
String sql = "";
sql = "select * from book_comment order by createDate desc";
v = dbconn.ListOfMapData(sql);
return v;
}
/**
* 删除评论
* @param id
* @throws SQLException
* @throws IOException
*/
public void deleteBookCommon(String id)throws SQLException,IOException
{
String sql = "";
sql = "delete from book_comment where id = '"+id+"' ";
dbconn.execute(sql);
}
/**
* 根据ID找到相应的图书评论
* @param id
* @return Vector
* @throws SQLException
* @throws IOException
*/
public Vector getBookCommonById(String id)throws SQLException,IOException
{
Vector v = null;
String sql = "";
sql = "select * from book_comment where id='"+id+"' ";
v = dbconn.ListOfMapData(sql);
return v;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -