教程中国
PHOTOSHOP CS9.0中文版 MAYA 8.5 FOR WINDOWS Corel Painter v9.0 Flash MX2004 中文版 Illustrator cs2 中文版
VC++6.0含sp6 中英文版 VB6.0 +sp6 简体中文版 Borland Delphi 7汉化版 MSDN for vb6.0中文版 Visual Studio 2005简体
教程中国下属 文件存储共享专家BIBIDU.COM 提供大型软件,教材,源码,电影,音乐,图书等下载 更多精品请点此进入
  您目前所在位置: 教程中国 >> Oracle >> 备份恢复 >> JSP连ORACLE的类文件 RSS订阅
JSP连ORACLE的类文件
教程(视频,书籍)下载:  ASP.NET AutoCAD 数据库 C# ASP java photoshop 网页设计 delphi 3dmax Flash C++ VB 张孝祥 实例   更多请进入BIBIDU搜索
IT搜索引擎   

  import java.io.Reader;
  import java.sql.*;
  import javax.servlet.ServletRequest;
  import javax.servlet.http.HttpServletRequest;
  import oracle.jdbc.driver.OracleResultSet;
  import oracle.sql.CLOB;
  
  public class Db_sql
  {
  
  /**
   * 构造函数,new Db_sql 的时候执行,调用 connect() 连接ORACLE数据库
   */
   public Db_sql(String s, String s1, String s2, String s3, String s4)
   throws Exception
   {
   isClosed = false;
   host = s.trim();
   port = s1.trim();
   sid = s2.trim();
   user = s3.trim();
   password = s4.trim();
   connMgr = DBConnectionManager.getInstance();
   connect();
   }
  
  /**
   * 连接ORACLE数据库
   */
   public boolean connect()
   throws Exception
   {
   String s = "jdbc:oracle:thin:@" + host + ":" + port + ":" + sid;
   conn = connMgr.getConnection(user, s, user, password);
   return true;
   }
  
  /**
   * 是否自动 COMMIT
   */
   public void setAutoCommit(boolean flag)
   throws SQLException
   {
   bAutoCommit = flag;
   conn.setAutoCommit(flag);
   }
  
  /**
   * 没有设置成自动 COMMIT ,调用该方法才会 COMMIT
   */
   public void commit()
   throws SQLException
   {
   if(!bAutoCommit)
   conn.commit();
   }
  
  /**
   * 没有设置成自动 COMMIT ,调用该方法才会 ROLL BACK
   */
   public void rollback()
   throws SQLException
   {
   if(!bAutoCommit)
   conn.rollback();
   }
  
  /**
   * 执行 SQL ,返回执行结果 TRUE/FALSE
   */
   public ResultSet query(String s)
   throws Exception
   {
   if(stmt == null)
   stmt = conn.createStatement();
   if(result != null)
   {
   result.close();
   result = null;
   }
   result = stmt.executeQuery(s);
   return result;
   }
  
   public void queryLarge(String s, String s1)
   throws Exception
   {
   stmt.execute(s);
   ResultSet resultset = stmt.getResultSet();
   if(resultset.next())
   {
   CLOB clob = ((OracleResultSet)resultset).getCLOB(1);
   clob.putChars(1L, s1.toCharArray());
   }
   resultset.close();
   }
  
  /**
   * 把结果集里的指针下移一位
   */
   public boolean next()
   throws SQLException
   {
   return result.next();
   }
  
  /**
   * 取得当前记录的 INT 类型字段值,前后去空格
   */
   public int getInt(String s)
   throws SQLException
   {
   return result.getInt(s.trim());
   }
  
  /**
   * 取得当前记录的 STRING 类型字段值,前后去空格
   */
   public String getString(String s)
   throws SQLException
   {
   return result.getString(s.trim());
   }
  
  /**
   * 取得当前记录的 SHORT 类型字段值,前后去空格
   */
   public short getShort(String s)
   throws SQLException
   {
   return result.getShort(s.trim());
   }
  
  
  /**
   * 取得当前记录的 LONG 类型字段值,前后去空格
   */
   public long getLong(String s)
   throws SQLException
   {
   return result.getLong(s.trim());
   }
  
  
  /**
   * 取得当前记录的 DATE 类型字段值,前后去空格
   */
   public Date getDate(String s)
   throws SQLException
   {
   return result.getDate(s.trim());
   }
  
  
  /**
   * 取得当前记录的 TIME 类型字段值,前后去空格
   */
   public Time getTime(String s)
   throws SQLException
   {
   return result.getTime(s.trim());
   }
  
  /**
   * 取得当前记录的 FLOAT 类型字段值,前后去空格
   */
   public float getFloat(String s)
   throws SQLException
   {
   return result.getFloat(s.trim());
   }
  
  /**
   * 取得当前记录的 DOUBLE 类型字段值,前后去空格
   */
   public double getDouble(String s)
   throws SQLException
   {
   return result.getDouble(s.trim());
   }
  
  /**
   * 取得当前记录的 BOOLEAN 类型字段值,前后去空格
   */
   public boolean getBoolean(String s)
   throws SQLException
   {
   return result.getBoolean(s.trim());
   }
  
  /**
   * 取得当前记录的 CLOB 类型字段值
   */
   public String getText(String s)
   throws SQLException
   {
   String s1 = "";
   char ac[] = new char[200];
   CLOB clob = (CLOB)result.getObject(s);
   if(clob == null)
   return null;
   Reader reader = clob.getCharacterStream();
   int i;
   try
   {
   while((i = reader.read(ac, 0, 200)) != -1)
   s1 = s1 + new String(ac, 0, i);
   }
   catch(Exception exception1)
   {
   throw new SQLException(exception1.getMessage());
   }
   finally
   {
   try
   {
   reader.close();
   }
   catch(Exception _ex) { }
   }
   return s1;
   }
  
  /**
   * 关闭数据库连接,执行 COMMIT,RELEASE 动作
   */
   public boolean close()
   throws SQLException
   {
   if(result != null)
   {
   result.close();
   result = null;
   }
   if(stmt != null)
   {
   stmt.close();
   stmt = null;
   }
   conn.setAutoCommit(true);
   connMgr.freeConnection(user, conn);
   connMgr.release(user);
   isClosed = true;
   return true;
   }
  
  /**
   * 没有调用 close() 时,执行 close()
   */
   protected void finalize()
   throws SQLException
   {
   if(!isClosed)
   close();
   }
  
  /**
   * 取得 HTTP 参数值,所有得到的值都做了
   * String (request.getParameter(s.trim()).trim().getBytes("ISO8859_1"), "GB2312") 处理
   */
   public static String getParameter(HttpServletRequest httpservletrequest, String s)
   {
   try
   {
   if(httpservletrequest.getParameter(s.trim()) != null)
   return new String(httpservletrequest.getParameter(s.trim()).trim().getBytes("ISO8859_1"), "GB2312");
   else
   return null;
   }
   catch(Exception _ex)
   {
   return httpservletrequest.getParameter(s.trim());
   }
   }
  

来源:upschool.com.cn
作者:
关键字:类文件
发表日期:2007-1-6 0:44:52

网页显示有限 阅读全文请下载本文完整版WORD文档

上一篇:PHP连ORACLE的类文件   下一篇:[范例]对象库的使用


2008-12-2 6:03:27
本文的相类似文章
  • PHP连ORACLE的类文件
  • 用C++ 产生 SQL*Loader 各类文件
  • ASP在线升级类文件
  • 如何在Java程序中运行外部类文件
  • C++产生SQL*Loader各类文件
  • 当你的Studio.NET出现Automation Server Cannot Create Object时,禁止添加页面及类文件时的解决方案~~
  • 使用javap深入查看类文件
  • ASP在线升级类文件
  • 在学习中进步 在进步中成长 教程中国相随您的成长之路
    华腾联合科技股份有限公司版权所有
    广告联系:Rosibo@163.com