解决反复插入info问题
This commit is contained in:
@@ -4,6 +4,7 @@ import com.hellogithub.entity.githubEntity;
|
|||||||
import com.hellogithub.entity.projectEntity;
|
import com.hellogithub.entity.projectEntity;
|
||||||
import com.hellogithub.entity.userEntity;
|
import com.hellogithub.entity.userEntity;
|
||||||
import com.hellogithub.utils.JdbcUtils;
|
import com.hellogithub.utils.JdbcUtils;
|
||||||
|
import com.mysql.cj.jdbc.JdbcConnection;
|
||||||
import org.apache.commons.dbutils.QueryRunner;
|
import org.apache.commons.dbutils.QueryRunner;
|
||||||
import org.apache.commons.dbutils.handlers.BeanListHandler;
|
import org.apache.commons.dbutils.handlers.BeanListHandler;
|
||||||
|
|
||||||
@@ -19,8 +20,15 @@ public class githubDao {
|
|||||||
public int ins_Github_info (int projectId, String avatar,String name, String starImgUrl, int starCount, String mainLanguage, String isActive, int subscriber, int issues, String isOrganization, String defaultBranch, int forks, String protocol, String version){
|
public int ins_Github_info (int projectId, String avatar,String name, String starImgUrl, int starCount, String mainLanguage, String isActive, int subscriber, int issues, String isOrganization, String defaultBranch, int forks, String protocol, String version){
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
Connection connection = null;
|
Connection connection = null;
|
||||||
int rs = 0 ;
|
ResultSet rs = null;
|
||||||
|
String sql1 = "SELECT * FROM githubinfo WHERE projectId = ?;";
|
||||||
|
int back = 0 ;
|
||||||
try {
|
try {
|
||||||
|
Connection conn = JdbcUtils.getConnection();
|
||||||
|
PreparedStatement prep = conn.prepareStatement(sql1);
|
||||||
|
prep.setInt(1,projectId);
|
||||||
|
rs = prep.executeQuery();
|
||||||
|
if(rs == null){
|
||||||
connection = JdbcUtils.getConnection();
|
connection = JdbcUtils.getConnection();
|
||||||
String Sql = "INSERT INTO githubinfo(id,projectId,avatar,name,starImgUrl,starCount,mainLanguage,isActive,subscriber,issues,isOrganization,defaultBranch,forks,protocol,version,isVaild) VALUES(null,?,?,?,?,?,?,?,?,?,?,?,?,?,?,0);";
|
String Sql = "INSERT INTO githubinfo(id,projectId,avatar,name,starImgUrl,starCount,mainLanguage,isActive,subscriber,issues,isOrganization,defaultBranch,forks,protocol,version,isVaild) VALUES(null,?,?,?,?,?,?,?,?,?,?,?,?,?,?,0);";
|
||||||
preparedStatement = connection.prepareStatement(Sql);
|
preparedStatement = connection.prepareStatement(Sql);
|
||||||
@@ -40,15 +48,18 @@ public class githubDao {
|
|||||||
preparedStatement.setInt(12, forks);
|
preparedStatement.setInt(12, forks);
|
||||||
preparedStatement.setString(13, protocol);
|
preparedStatement.setString(13, protocol);
|
||||||
preparedStatement.setString(14, version);
|
preparedStatement.setString(14, version);
|
||||||
rs = preparedStatement.executeUpdate();
|
back = preparedStatement.executeUpdate();
|
||||||
return rs;
|
}else{
|
||||||
|
return back;
|
||||||
|
}
|
||||||
|
return back;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
JdbcUtils.closeConnection(preparedStatement, connection);
|
JdbcUtils.closeConnection(preparedStatement, connection);
|
||||||
}
|
}
|
||||||
return rs;
|
return back;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<githubEntity> ret_Github_info(int projectid){
|
public List<githubEntity> ret_Github_info(int projectid){
|
||||||
|
Reference in New Issue
Block a user