通用数据库操作BEAN

通用数据库操作BEAN

package pkgCDB;

import java.text.*;
import java.util.*;
import java.sql.*;

public class clsCDB
{
String sDBDriver = "";
String sConnStr = "";
String sHint = "";
ResultSet rs = null;
Connection conn = null;
Statement stmt = null;

public String getHint()
{
return sHint;
}

public void setDBDriver(String s)
{
sDBDriver = "" + s;
}

public String getDBDriver()
{
return sDBDriver;
}

public String getConnStr()
{
return sConnStr;
}

public void setConnStr(String s)
{
sConnStr = "" + s;
}

public ResultSet getResultSet()
{
return rs;
}

//Initialize the database
public boolean Initialization(String dbDrive,String dbConn)
{
sDBDriver = dbDrive;
sConnStr = dbConn;
return Initialization();
}

public boolean Initialization()
{
try
{
Class.forName(sDBDriver);
sHint = "Initialization sucessfully";
return true;
}
catch(java.lang.ClassNotFoundException e) {
sHint = "Initialization : " + e.getMessage();
return false;
}
}

//A common function perhaps usable
public String chkStr(String inStr)
{
StringBuffer result = new StringBuffer("");
char cc;

if (inStr != null)
{
for (int i = 0; i < inStr.length(); i++)
{
cc = inStr.charAt(i);
if (cc == )
{
result.append();
}
result.append(cc);
}
}
return result.toString();
}

//execute a SQL statement with recordset returned
public ResultSet executeQuery(String sql)
{
rs = null;
try
{
conn = DriverManager.getConnection(sConnStr);
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex)
{
sHint = "executeQuery: " + ex.getMessage();
}
return rs;
}

//execute a SQL statement without returning recordset
public boolean executeUpdate(String sql)
{
try
{
conn = DriverManager.getConnection(sConnStr);
stmt = conn.createStatement();
stmt.executeUpdate(sql);
return true;
}
catch(SQLException ex)
{
sHint = "executeUpdate: " + ex.getMessage();
return false;
}
}

//Close connections
public boolean closeConn()
{

try
{
if (rs!=null)
rs.close();
if (stmt!=null)
stmt.close();
if (conn!=null)
conn.close();
return true;
}
catch(SQLException ex)
{
sHint = "closeConn: " + ex.getMessage();
return false;
}
}
}


最热门点击排行:
1.> db2 oracle
2.> db2 个人版
3.> db2 时间
4.> db2 版本
5.> db2 自定义函数
6.> db2 load
7.> sybase数据库
8.> sybase 安装
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值