您的位置:首页 >> 编程开发 >> Java >> 数据库 >> 正文
数据库 RSS
 

jsp连接sqlserver调用数据源方法

http://www.rdxx.com 02年03月30日 11:19 互联网 我要投稿

关键词: 数据源 , 方法 , 调用 , SQLServer , JSP连接 , SQL , 数据 , 连接 , JSP
 

     for(int i=0;i<numberOfColumns;i++){
      if(rs.getObject(i+1)==null){
       strArrayTemp[i]= "";
      }else{
       strArrayTemp[i]=rs.getObject(i+1).toString();
      }
     }
     ArrayRs.add(strArrayTemp);
    }
    return (ArrayList)ArrayRs.clone();
  }catch(Exception e){
   System.out.println("query error:" + e.getMessage());
  }finally{
   if (stmt != null) {
    stmt.close();
   }
   if (con != null) {
    con.close();
   }
  }
  return ArrayRs;
 }
 /**
  * @param executeInsert插入数据方法
  * @return 插入条数是否成功(boolean)
  */
 public boolean executeInsert(String strSql) throws SQLException{
  rs=null;
  try{
   con=source.getConnection();
   stmt=con.createStatement();
   
   con.setAutoCommit(true);
   int i=stmt.executeUpdate(strSql);

   if(i==1){
    return (true);
   }
  }catch(Exception e){
   System.out.println("Insert error:"+e.getMessage());
  }finally{
   if (stmt != null) {
    stmt.close();
   }
   if (con != null) {
    con.close();
   }
  }
  return (false);
 }
 /**
  * @param executeUpdate修改数据方法
  * @return 修改数据数(int)
  */
 public int executeUpdate(String strSql) throws SQLException{
  rs=null;
  int j=0;
  try{
   con=source.getConnection();
   stmt=con.createStatement();
   con.setAutoCommit(false);
   
   j=stmt.executeUpdate(strSql);
   if(j>0){
    con.commit();
   }else{
    con.rollback();
   }
  }catch(Exception e){
   System.out.println("update error:"+e.getMessage());
  }finally{
   if (stmt != null) {
    stmt.close();
   }
   if (con != null) {
    con.close();
   }
  }
  return j;
 }
 /**
  * @param executeDelete删除数据方法
  * @return 删除数据数(int)
  */
 public int executeDelete(String strSql) throws SQLException{
  rs=null;

9 7 3 1 2 3 4 8 :


 
 
标签: 数据源 , 方法 , 调用 , SQLServer , JSP连接 , SQL , 数据 , 连接 , JSP 打印本文
 
 
  热点搜索
 
 
 



Valid XHTML 1.0 Transitional
Copyright ©2005 - 2008 Rdxx.Com,All Rights Reserved
收藏本页
收藏本站