preparedStatement问号的深入理解
生活随笔
收集整理的這篇文章主要介紹了
preparedStatement问号的深入理解
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
/*** 根據表名查詢總條數;* @param tableName* @return*/public int getCount(String tableName){String sql="select count(*) from "+tableName;Connection conn=getConnection();PreparedStatement pst=null;?? ??? ?ResultSet rs=null;int count=0;try {pst = conn.prepareStatement(sql);//pst.setString(1,tableName);rs=pst.executeQuery();if(rs.next())count=rs.getInt(1);} catch (SQLException e) {e.printStackTrace();}finally{closeAll(rs, pst, conn);}return count;}
總結:?
PreparedStatement只能用來為可以加引號’的參數(如參數值)設置動態參數,即用?占位,不可用于表名、字段名等。
總結
以上是生活随笔為你收集整理的preparedStatement问号的深入理解的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ajax技术实战-张晨光-专题视频课程
- 下一篇: JSON开发详解-张晨光-专题视频课程