读取相同数据库,相同表,相同内容。
使用线程读,每秒读一次。
查看任务管理器,Tomcat6.exe内存使用情况:
SSH代码:使用75兆左右,
SQL代码:使用65兆左右。这是为什么?SSH能减少内存使用吗?
谢谢。SSH代码:
public String findPlcAmsNetIdByWind_Code(String wind_Code){
List list = new ArrayList();
Session s = null; 
        try {
            s = HibernateUtil.getSession();
            Transaction tx=null;
            tx=s.beginTransaction();
            Query query = s.createQuery("select plcAmsNetId From PlcAmsNetID where wind_Code= ?");
            list = query.setParameter(0, wind_Code).list();
            tx.commit();
            
            return list.get(0).toString();
        } finally {
            HibernateUtil.closeSession();
        }
}
SQL代码:
public String findPlcAmsNetIdByWind_Code_BySql(String wind_Code){
String id = null;

    String driver = "com.mysql.jdbc.Driver";
    String url = "jdbc:mysql://localhost:3306/test";
    String user = "root"; 
    String password = "root";
    Statement  statement = null;
    try { 
     // 加载驱动程序
     Class.forName(driver);
     // 连续数据库
     Connection conn = DriverManager.getConnection(url, user, password);
     if(!conn.isClosed())
     // statement用来执行SQL语句
      statement =  conn.createStatement();
     // 要执行的SQL语句
     String sql = "select plcAmsNetId from PlcAmsNetID where wind_Code = '"+wind_Code+"'";
     // 结果集
     ResultSet rs = statement.executeQuery(sql);
     
     while(rs.next()) {
      
          // 选择sname这列数据
          id = rs.getString("plcAmsNetId");
 
          // 首先使用ISO-8859-1字符集将name解码为字节序列并将结果存储新的字节数组中。
          // 然后使用GB2312字符集解码指定的字节数组
          
         }          rs.close();
     
     conn.close();     } catch(ClassNotFoundException e) {
     System.out.println("Sorry,can`t find the Driver!"); 
     e.printStackTrace();
    } catch(SQLException e) {
     e.printStackTrace();
    } catch(Exception e) {
     e.printStackTrace();
    }
    return id;
}