📄 bbsnext.java
字号:
package building;
import java.util.*;
import java.sql.*;
import javax.sql.*;
public class BBSnext {
private int bbsnextId = 0 ;
private int bbsId = 0 ;
private int userId = 0 ;
private String contents = null ;
private String subtime = null ;
private String userName = "";
public BBSnext(){
}
/*
* 跟帖Id set and get
*/
public void setBbsnextId(int bbsnextId){
this.bbsnextId = bbsnextId ;
}
public int getBbsnextId(){
return (bbsnextId);
}
/*
* 主帖Id set and get
*/
public void setBbsId(int bbsId){
this.bbsId = bbsId ;
}
public int getBbsId(){
return (bbsId) ;
}
/*
* 发帖者Id set and get
*/
public void setUserId(int userId){
this.userId = userId ;
}
public int getUserId(){
return (userId);
}
/*
* 跟帖内容contents set and get
*/
public void setContents(String contents){
this.contents = contents ;
}
public String getContents(){
return (contents);
}
/*
* 跟帖发表时间subtime set and get
*/
public void setSubtime(String subtime){
this.subtime = subtime ;
}
public String getSubtime(){
return (subtime) ;
}
/**
* 发表者的姓名userName set and get
*/
public void setUserName(String userName)
{
this.userName = userName;
}//End of setUserName
public String getUserName()
{
return(userName);
}//End of getUserName
/**
* 数据库操作
*/
/**
* 添加新的BBSnext
*/
public boolean addNewBBSnext(DB db)
throws SQLException
{
String strSql = null;
ResultSet rs = null;
int iMax = 0;
//查找最大的ID号
strSql = "select Max(bbsnextid) from BBSnext";
rs = db.OpenSql(strSql);
if (rs.next())
{
iMax = rs.getInt(1);
iMax++;
}//End of if
else
{
iMax = 1;
}//End of else
strSql = "insert into BBSnext values("
+ iMax + ","
+ bbsId + ","
+ userId + ",'"
+ contents + "','"
+ subtime + "')";
if ( db.ExecSql(strSql) == 0 )
{
//添加失败
return(false);
}//End of if
else
{
//添加成功
return(true);
}//End of else
}//End of addNewBBSnext
/**
* 按照bbsid查找相应的bbsnext信息
*/
public static Vector getInfoByBBSID(DB db,int bbsid)
throws SQLException
{
String strSql = null;
String strContents = null;
ResultSet rs1 = null;
ResultSet rs2 = null;
Vector bbsnextList = new Vector();
strSql = "select * from BBSnext where bbsid=" + bbsid;
rs1 = db.OpenSql(strSql);
while ( rs1.next() )
{
BBSnext bn = new BBSnext();
bn.setBbsId(bbsid);
bn.setBbsnextId(rs1.getInt("bbsnextid"));
bn.setUserId(rs1.getInt("userid"));
strContents = rs1.getString("contents");
bn.setContents(strContents.replaceAll("\n","<br>"));
bn.setSubtime(rs1.getString("subtime"));
strSql = "select username from Users where id=" + bn.getUserId();
rs2 = db.OpenSql(strSql);
if ( rs2.next() )
{
bn.setUserName(rs2.getString("username"));
}//End of if
else
{
bn.setUserName("");
}//End of else
bbsnextList.add(bn);
}//End of while
return(bbsnextList);
}//End of getInfoByBBSID
}//End of class BBSnext
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -