当前位置:Gxlcms > 数据库问题 > 连接Mysql数据库

连接Mysql数据库

时间:2021-07-01 10:21:17 帮助过:23人阅读

6、处理结果

  • 两种情况: 
    1. 执行更新返回的是本次操作影响到的记录数。
    2. 执行查询返回的结果是一个ResultSet对象。
  • ResultSet包含符合SQL语句中条件的所有行,并且它通过一套get方法提供了对这些 
    行中数据的访问。
  • 使用结果集(ResultSet)对象的访问方法获取数据:
while(rs.next()){   
            String name = rs.getString("name") ;   
            String pass = rs.getString(1) ; // 此方法比较高效   
        }   

(列是从左到右编号的,并且从列1开始) 
7、关闭JDBC对象 
操作完成以后要把所有使用的JDBC对象全都关闭,以释放JDBC资源,关闭顺序和声 
明顺序相反: 
1、关闭记录集 
2、关闭声明

      if(rs != null){   // 关闭记录集   
    try{   
        rs.close() ;   
    }catch(SQLException e){   
        e.printStackTrace() ;   
    }   
      }   
      if(stmt != null){   // 关闭声明   
    try{   
        stmt.close() ;   
    }catch(SQLException e){   
        e.printStackTrace() ;   
    }   
      }   
      if(conn != null){  // 关闭连接对象   
     try{   
        conn.close() ;   
     }catch(SQLException e){   
        e.printStackTrace() ;   
     }   
      }  
 

连接Mysql数据库

标签:host   etc   取数   请求   需要   标记   字符   span   语句   

人气教程排行