📄 clubtopicilike.java
字号:
package com.gamvan.club.topic;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import com.gamvan.conn.ConnClub;
public class ClubTopicIlike {
private int likeID = 0;
private int myUserID = 0;
private int topicID = 0;
private String lastTime = "";
private String topic = "";
private String topicUserName="";
private String topicLastReTime = "";
private String myUserName = "";
private String ccName="";
private int ccID = 0;
private int topicUserID=0;
private String message = "";
ConnClub bridge = new ConnClub();
//格式化当前时间
java.text.SimpleDateFormat isNow = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private String now = isNow.format(new java.util.Date());
public boolean delLike(String[] ids) throws Exception{
boolean bea = false;
int id = 0;
String sqlCommand = "";
for(int i=0; i<ids.length; i++){
id = Integer.parseInt(ids[i]);
Connection con = bridge.getConnection();
try{
sqlCommand = "delete From GVclubTopicIlike where likeID=?";
PreparedStatement pps = con.prepareStatement(sqlCommand);
pps.setInt(1, id);
pps.executeUpdate();
pps.close();
bea = true;
}catch(Exception e){
message =e.toString();
}finally{
con.close();
}
}
if(bea){
message = "操作成功!";
}else{
message = "操作中断,遭遇错误!";
}
return bea;
}
public boolean doLike(int topicid, int userid) throws Exception{
boolean bea = false;
ClubTopicInfo cti = new ClubTopicInfo();
if(cti.topicInfo(topicid)){
topic = cti.getTopic();
topicLastReTime = cti.getLastReTime();
topicUserName = cti.getUserName();
ccID = cti.getCCID();
topicUserID = cti.getUserID();
if(selectIlike(topicid, myUserID)){
message = topic + "<br/><br/>操作终止!您已经订阅过本主题!";
}else{
bea = addIlike(topicid);
}
}else{
message = "你所收藏的主题不存在或已被删除。";
bea = false;
}
return bea;
}
public boolean addIlike(int topicid) throws Exception{
boolean bea = false;
String sqlCommand = "";
Connection con = bridge.getConnection();
try{
sqlCommand = "Insert into GVclubTopicIlike(topicID, myUserID, myUserName," +
"addTime, lastTime, topic, topicUserName, topicLastReTime, ccID, topicUserID)" +
" Values(?,?,?,?,?,?,?,?,?,?)";
PreparedStatement pps = con.prepareStatement(sqlCommand);
pps.setInt(1,topicid);
pps.setInt(2,myUserID);
pps.setString(3,myUserName);
pps.setString(4,now);
pps.setString(5,now);
pps.setString(6,topic);
pps.setString(7,topicUserName);
pps.setString(8,topicLastReTime);
pps.setInt(9,ccID);
pps.setInt(10,topicUserID);
pps.executeUpdate();
pps.close();
bea = true;
message = topic+"<br/><br/>订阅成功!";
}catch(Exception e){
message = "订阅主题过程中发生意外错误,本次操作失败!";
}finally{
con.close();
}
return bea;
}
public boolean selectIlike(int topicid, int userid) throws Exception{
boolean bea = false;
String sqlCommand = "";
Connection con = bridge.getConnection();
ResultSet rs;
try{
sqlCommand = "Select * From GVclubTopicIlike where topicID=? and myUserID=?";
PreparedStatement pps = con.prepareStatement(sqlCommand);
pps.setInt(1,topicid);
pps.setInt(2,userid);
rs = pps.executeQuery();
if(rs.next()){
likeID = rs.getInt(1);
bea = true;
}
rs.close();
pps.close();
}catch(Exception e){
bea = false;
}finally{
con.close();
}
return bea;
}
public String getMessage(){
return this.message;
}
public void setMyUserID(int myUserID){
this.myUserID = myUserID;
}
public void setMyUserName(String myUserName){
this.myUserName = myUserName;
}
public void setTopicID(int topicID){
this.topicID = topicID;
}
public int getLikeID(){
return this.likeID;
}
public int getMyUserID(){
return this.myUserID;
}
public String getTopicUserName(){
return this.topicUserName;
}
public int getTopicID(){
return this.topicID;
}
public String getTopicLastReTime(){
return this.topicLastReTime;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -