输入banner图图片脚本导航/分类

JDBC学习笔记(1)

  if(stm != null){
      stm.close();
  }
  if (conn != null){
     conn.close();  
  }

    
II.对于select(即有查询结果的操作,六个步骤)

    1、注册驱动类

 Class.forName("oracle.jdbc.driver.OracleDriver");

    2、创建连接

String url="jdbc:oracle:thin:@localhost:1521:xe";
Connection conn = DriverManager.getConnection(url,"hr","hr");

    3、创建Statement

Statement stm = conn.createStatement();

    4、执行SQL语句   

 sql = "select...";
 ResultSet rs = stm.executeQuery(sql);

    5、处理查询结果

 while(rs.next()){
     //获取字段
     Xxx x = rs.getXxx("字段名");
     Xxx x = rs.getXxx(columnIndex);
 }

    5、释放资源(先创建的后关闭)//先创建的后释放

  if(rs != null){
      rs.close();
  } 
  if(stm != null){
      stm.close();
  }
  if (conn != null){
     conn.close();  
  }


JDBC学习笔记(1)

标签:连接数据库   接口   java技术