jdbc 一个类中方法的优化
public Article queryOneArticleByArticleId(String articleId) {
Article article=null;
DBManager dbc=Factory.getDBManagerInstance();
Connection conn=null;
PreparedStatement pstmt=null;
ResultSet rs=null;
/****还得使readCount加1******/
String sql0="update article set readCount=readCount+1 where articleId=?";
String sql="select * from article where articleid=?";
try {
conn=dbc.getConn();
pstmt=conn.prepareStatement(sql0);
pstmt.setString(1, articleId);
pstmt.executeUpdate();
/******问题在这句*********************/
pstmt.close();//这里到底要不要关嘛
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, articleId);
rs=pstmt.executeQuery();
while(rs.next()){
·····略
问题:我想问的是,当执行两句sql语句时候,执行完第一句sql语句后以后,要不要pstmt.close()这句呢,
不要会不会不安全?或者无所谓呢?(实验的时候要不要这句都正常运行的,但是我想选择一种好的方法)