发布文章贡献值更新

This commit is contained in:
sjm
2023-07-06 23:43:43 +08:00
parent a8f28982e6
commit 0f5564cbe9

View File

@@ -141,13 +141,19 @@ public class articleDao {
public int insertArticle(int userid,String articleContent,String articleTitle,String articleIco){
Connection conn = null;
PreparedStatement preparedStatement = null;
Connection conn1 = null;
PreparedStatement preparedStatement1 = null;
String sql = "INSERT INTO article(articleId,userId,articleContent,publishTime,isValid,readCount,articleTitle,articleIco)\n" +
" VALUES(NULL,?,?,?,1,0,?,?);";
String sql1 = "UPDATE user SET contributionValue = contributionValue+5 WHERE userId = ?";
Date time= new java.sql.Date(new java.util.Date().getTime());
int bool = 0;
try{
conn = JdbcUtils.getConnection();
preparedStatement = conn.prepareStatement(sql);
conn1 = JdbcUtils.getConnection();
preparedStatement1 = conn1.prepareStatement(sql1);
preparedStatement1.setInt(1,userid);
preparedStatement.setInt(1,userid);
preparedStatement.setString(2, articleContent);
preparedStatement.setDate(3, time);
@@ -155,9 +161,12 @@ public class articleDao {
preparedStatement.setString(5, articleIco);
bool = preparedStatement.executeUpdate();
preparedStatement1.executeUpdate();
JdbcUtils.closeConnection(preparedStatement, conn);
JdbcUtils.closeConnection(preparedStatement1, conn1);
}catch (Exception e){
JdbcUtils.rollBackTransaction(conn);
JdbcUtils.rollBackTransaction(conn1);
e.printStackTrace();
}
return bool;