国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JSP > 正文

網上找到的JSP聯接Oracle的原碼

2024-09-05 00:19:27
字體:
來源:轉載
供稿:網友


收集最實用的網頁特效代碼!


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());
}
}
private string host;
private string port;
private string database;
private string user;
private string password;
private string sid;
private boolean bautocommit;
public resultset result;
public statement stmt;
public int affectedrows;
public connection conn;
private boolean isclosed;
private dbconnectionmanager connmgr;
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 阜新市| 耒阳市| 高雄市| 永定县| 温泉县| 孙吴县| 临沭县| 托克逊县| 莫力| 东山县| 肃北| 大丰市| 湘潭市| 龙口市| 南宁市| 堆龙德庆县| 武冈市| 平和县| 永寿县| 宜宾市| 丹巴县| 根河市| 潞西市| 林州市| 临西县| 谷城县| 哈巴河县| 昭苏县| 包头市| 鄯善县| 佛山市| 玛纳斯县| 赣榆县| 灌阳县| 临猗县| 萨嘎县| 凤凰县| 林西县| 宜春市| 昌宁县| 温州市|