jsp连oracle的类文件[1]

[入库:2005年8月28日] [更新:2007年3月24日]

本文简介:

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();

本文关键:jsp连oracle的类文件
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top