文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>通用数据库操作BEAN

通用数据库操作BEAN

时间:2010-09-23  来源:PerSector

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;
}
}
}
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载