ArrayList和Vector的区别,HashMap和Hashtable的区别
答:就ArrayList与Vector主要从二方面来说.
一.同步性:Vector是线程安全的,也就是说是同步的,而ArrayList是线程序不安全的,不是同步的
二.数据增长:当需要增长时,Vector默认增长为原来一培,而ArrayList却是原来的一半
就HashMap与HashTable主要从三方面来说。
一.历史原因:Hashtable是基于陈旧的Dictionary类的,HashMap是Java 1.2引进的Map接口的一个实现
二.同步性:Hashtable是线程安全的,也就是说是同步的,而HashMap是线程序不安全的,不是同步的
三.值:只有HashMap可以让你将空值作为一个表的条目的key或value
都属于
Map
接口的类,实现了将惟一键映射到特定的值上。
HashMap
类没有分类或者排序。它允许一个
null
键和多个
null
值。
Hashtable
类似于
HashMap
,但是不允许
null
键和
null
值。它也比
HashMap
慢,因为它是同步的。
posted @
2007-08-20 13:13 华梦行 阅读(249) |
评论 (0) |
编辑 收藏
Stack. 用来在ram中存放数据的地方 This lives in the general RAM (random-
access memory) area, but has direct support from the processor via its stack pointer. The stack pointer is moved down to create
new memory and moved up to release that memory. This is an extremely fast and efficient way to allocate storage, second only to registers. The Java compiler must know, while
it is creating the program, the exact size and lifetime of all the data that is stored on the stack, because it must generate the code to move the stack pointer up and down. This constraint places limits on the flexibility of your programs, so while some Java storage exists on the stack ?in particular, object handles ?Java objects are not placed on the stack.
Heap. This is a general-purpose pool of memory (also in the RAM area) where all Java objects live. The nice thing about the heap is that, unlike the stack, the compiler doesn't need to know how much storage it needs to allocate from the heap or how long that storage must stay on the heap. Thus, there's a great deal of flexibility in using storage on the heap. Whenever you need to create an object, you simply write the code to create it using new and the storage is allocated on the heap when that code is executed. And of course there's a price you pay for this flexibility: it takes more time to allocate heap storage.
. 栈(stack)与堆(heap)都是Java用来在Ram中存放数据的地方。
2. 栈的优势是,存取速度比堆要快,仅次于直接位于CPU中的寄存器。但缺点是,存在栈中的数据大小与生存期必须是确定的,缺乏灵活性。另外,栈数据可以共享,详见第3点。堆的优势是可以动态地分配内存大小,生存期也不必事先告诉编译器,Java的垃圾收集器会自动收走这些不再使用的数据。但缺点是,由于要在运行时动态分配内存,存取速度较慢。
3. Java中的数据类型有两种。基本类型(primitive types), 共有8种,即int, short, long, byte, float, double, boolean, char。存在于栈中。另一种是包装类数据,如Integer, String, Double等将相应的基本数据类型包装起来的类。这些类数据全部存在于堆中.
posted @
2007-08-20 13:08 华梦行 阅读(161) |
评论 (0) |
编辑 收藏
Boolean.parseBoolean("Strrrr"); false
只有String 在忽略大小写的情况小“true”才会返回true
posted @
2007-08-20 10:18 华梦行 阅读(501) |
评论 (0) |
编辑 收藏
String strSource=request.getHeader("Referer")
posted @
2007-08-17 10:29 华梦行 阅读(70) |
评论 (0) |
编辑 收藏
strReturn= sql.replaceAll("(&)|(
\\^)|(')|(/)|(;)|(:)|(_)|(%)|(\")|(\n)|(\\*)|(\\+)|(\\[)|(\\])|(\\})|(\\{)|(\\n)|(\\|)","");
public static String dealSql(String sql){
String strReturn="";
if (sql==null)
strReturn="";
else{
try{
strReturn= sql.replaceAll("(&)|(
\\^)|(')|(/)|(;)|(:)|(_)|(%)|(\")|(\n)|(\\*)|(\\+)|(\\[)|(\\])|(\\})|(\\{)|(\\n)|(\\|)","");
}catch(Exception e){
System.out.println(e.toString());
strReturn="";
}
}
return strReturn;
}
posted @
2007-08-16 18:10 华梦行 阅读(107) |
评论 (0) |
编辑 收藏
/*
* PathWsInterUnit.java
*
* Created on 2007年8月16日, 下午12:52
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package path.ws.interUnit;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import path.crm.entity.CRM_Interunit;
import path.crm.manager.InterUnitManager;
/**
*
* @author ljl
*/
@WebService()
public class PathWsInterUnit {
/**
* Web service operation 客户新增
* @param pwsStrWebSiteID 网站id
* @param pwsStrInterUnitName 客户名称
* @param pwsStrTel 电话
* @param pwsStrMobile 手机
* @param pwsStrFax 传真
* @param pwsStrCorpName 公司名称
* @param pwsStrEmail 公司邮件
* @param pwsStrMemo 详细信息
* @return "success" : 添加成功 userexisted: "用户已存在" emailexisted: 该邮件已经被使用过了 fail: 添加失败
*/
@WebMethod
public String pathWsInterUnitAdd(@WebParam(name = "pwsStrWebSiteID") String pwsStrWebSiteID, @WebParam(name = "pwsStrInterUnitName") String pwsStrInterUnitName, @WebParam(name = "pwsStrTel") String pwsStrTel, @WebParam(name = "pwsStrMobile") String pwsStrMobile, @WebParam(name = "pwsStrFax") String pwsStrFax, @WebParam(name = "pwsStrCorpName") String pwsStrCorpName, @WebParam(name = "pwsStrEmail") String pwsStrEmail, @WebParam(name = "pwsStrMemo") String pwsStrMemo) {
String strReturn;
InterUnitManager im=new InterUnitManager();
//检查用户时候存在
if ("existed".equals(im.chkIfExistRcd(pwsStrInterUnitName,"InterUnitName")))
return "userexisted";
if ("existed".equals(im.chkIfExistRcd(pwsStrInterUnitName,"InterUnitName")))
return "emailexisted";
//检查邮件是否存在
try{
CRM_Interunit ci=new CRM_Interunit();
ci.setSerialNumber(pwsStrInterUnitName);
ci.setOrgTypeId("pathwebserviceorgnization");
ci.setCreatorTypeId(pwsStrWebSiteID);
ci.setName(pwsStrCorpName);
ci.setTelephone(pwsStrTel);
ci.setFax(pwsStrFax);
ci.setEmail(pwsStrEmail);
ci.setDescription(pwsStrMemo);
return im.insertInterunitWs(ci);
}catch(Exception e){
System.out.println(e.toString());
return "fail";
}
}
/**
* Web service operation 是否存在的服务 直接调用javabean
* @param pwsStrWebSiteId 网站id
* @param pwsStrChkName
* @param pwsStrChkModule 模块名 InterUnitName:检验客户是否存在 InterUnitEmail:邮件是否被注册过
* @return 不存在:notExisted 存在:existed 异常:"fail
*/
@WebMethod
public String pathWsCheckUserExist(@WebParam(name = "pwsStrWebSiteId") String pwsStrWebSiteId, @WebParam(name = "pwsStrChkName") String pwsStrChkName, @WebParam(name = "pwsStrChkModule") String pwsStrChkModule) {
// TODO implement operation
return new InterUnitManager().chkIfExistRcd(pwsStrChkName,pwsStrChkModule);
}
}
posted @
2007-08-16 14:19 华梦行 阅读(101) |
评论 (0) |
编辑 收藏
Server.xml :
<GlobalNamingResources>
<!-- Test entry for demonstration purposes -->
<Environment name="simpleValue" type="java.lang.Integer" value="30"/>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users -->
<Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>
<!--
<Resource
auth="Container"
name="jdbc/PathPlat"
type="javax.sql.DataSource"
password=""
driverClassName="net.sourceforge.jtds.jdbc.Driver"
maxIdle="50"
maxWait="5000"
username="sa"
url="jdbc:jtds:sqlserver://192.168.0.155:1433/pathplat;tds=8.0;lastupdatecount=true"
removeAbandoned="true"
removeAbandonedTimeout="60"
maxActive="100"/> -->
<Resource
name="jdbc/PathPlat"
auth="Container"
type="javax.sql.DataSource"
password=""
driverClassName="oracle.jdbc.driver.OracleDriver"
maxIdle="50"
maxWait="5000"
username="tep"
url="jdbc:oracle:thin:@192.168.0.166:1521:w"
removeAbandoned="true"
removeAbandonedTimeout="60"
maxActive="100"/>
</GlobalNamingResources>
context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/PathCrm" reloadable="true">
<ResourceLink global="jdbc/PathPlat" name="jdbc/PathPlat" type="javax.sql.DataSource"/>
</Context>
hibernate.cfg.xml:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.datasource">java:comp/env/jdbc/PathPlat</property>
<!-- SQL dialect -->
<!--<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>-->
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">false</property>
<mapping resource="/wms/entity/WmsAdjustStoreCmdt.hbm.xml"/>
<mapping resource="/wms/entity/WmsStorage.hbm.xml"/>
</session-factory>
</hibernate-configuration>
posted @
2007-08-15 10:44 华梦行 阅读(148) |
评论 (0) |
编辑 收藏
竖排格式:
Portrait 横排格式:landscape
posted @
2007-08-14 19:18 华梦行 阅读(132) |
评论 (0) |
编辑 收藏
If dtmDateLowerLimit is not null and dtmDateUpperLimit is not null then
temps := temps ||' AND DATEDIFF(''d'', to_date('''||to_char(dtmDateLowerLimit,'yyyy-mm-dd ')|| ' 00:00:00'||''',''yyyy-mm-dd HH24:mi:ss''), a.SendTime) >= 0 AND DATEDIFF(''d'', a.SendTime, to_date('''||to_char(dtmDateUpperLimit,'yyyy-mm-dd')|| ' 23:59:59'||''',''yyyy-mm-dd HH24:mi:ss'')) >= 0 ' ;
End If;
posted @
2007-08-13 11:14 华梦行 阅读(83) |
评论 (0) |
编辑 收藏
document.getElementById("ffff").readOnly=true;
readOnly O必须大写
posted @
2007-08-10 14:20 华梦行 阅读(108) |
评论 (0) |
编辑 收藏
Session session = HibernateUtil.getSession();
Criteria crit = session.createCriteria(entityClass);
crit.add(Restrictions.eq("orgTypeId", orgId));
crit.add(Restrictions.eq("StructID", strTypeid));
List entities = crit.list();
populate(sheet, entities);
Hibernate 条件查询
/*
* ExportManager.java
*
* Created on 2006年7月30日, 下午2:40
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package path.system.manager;
import java.io.*;
import java.util.List;
import java.util.Date;
import java.sql.Timestamp;
import java.lang.reflect.*;
import java.math.BigDecimal;
import jxl.*;
import jxl.write.*;
import org.hibernate.Session;
import org.hibernate.Query;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import path.system.manager.HibernateUtil;
import path.util.DoNumber;
/**
*
* @author zhaoming
*/
public class ExportManager {
private Class entityClass;
private Field[] fields;
private Class[] fieldTypes;
private static WritableCellFormat integerFormat = new WritableCellFormat(NumberFormats.INTEGER);
private static WritableCellFormat floatFormat = new WritableCellFormat(new NumberFormat("#.####"));
private static WritableCellFormat dateFormat = new WritableCellFormat(new DateFormat("yyyy-MM-dd"));
public ExportManager() {
}
/**
* 输出excel
* @param is 原始excel模版输入流
* @param os 目的输出流,这里是ServletOutputStream
*/
public void exportExcel(InputStream is, OutputStream os, String orgId) {
WritableWorkbook wb = null;
try {
wb = Workbook.createWorkbook(os, Workbook.getWorkbook(is));
WritableSheet sheet = wb.getSheet(0);
init(sheet);
Session session = HibernateUtil.getSession();
Criteria crit = session.createCriteria(entityClass);
crit.add(Restrictions.eq("orgTypeId", orgId));
List entities = crit.list();
populate(sheet, entities);
wb.write();
} catch (Exception e) {
e.printStackTrace();
} finally {
try { wb.close(); } catch (Exception e) {}
}
}
public void exportExcelCd(InputStream is, OutputStream os, String orgId, String strTypeid) {
WritableWorkbook wb = null;
try {
wb = Workbook.createWorkbook(os, Workbook.getWorkbook(is));
WritableSheet sheet = wb.getSheet(0);
init(sheet);
Session session = HibernateUtil.getSession();
Criteria crit = session.createCriteria(entityClass);
crit.add(Restrictions.eq("orgTypeId", orgId));
crit.add(Restrictions.eq("StructID", strTypeid));
List entities = crit.list();
populate(sheet, entities);
wb.write();
} catch (Exception e) {
e.printStackTrace();
} finally {
try { wb.close(); } catch (Exception e) {}
}
}
private void init(WritableSheet sheet) throws Exception {
entityClass = Class.forName(sheet.getCell(0, 0).getContents().trim());
Cell[] fieldNames = sheet.getRow(1);
int len = fieldNames.length;
fields = new Field[len];
fieldTypes = new Class[len];
for (int i = 0; i < len; i++) {
fields[i] = entityClass.getDeclaredField(fieldNames[i].getContents().trim());
fieldTypes[i] = fields[i].getType();
}
}
private void populate(WritableSheet sheet, List entities) throws Exception {
for (int i = 0; i < entities.size(); i++) {
Object entity = entities.get(i);
for (int j = 0; j < fields.length; j++) {
fields[j].setAccessible(true);
WritableCell cell = getCell(i + 3, j, fields[j].get(entity));
sheet.addCell(cell);
}
}
}
private WritableCell getCell(int row, int col, Object value) {
if (fieldTypes[col] == String.class)
return new Label(col, row, (String) value);
if (fieldTypes[col] == long.class || fieldTypes[col] == Long.class)
return new jxl.write.Number(col, row, value == null ? 0 : ((Long) value).longValue(), integerFormat);
if (fieldTypes[col] == int.class || fieldTypes[col] == Integer.class)
return new jxl.write.Number(col, row, value == null ? 0 : ((Integer) value).intValue(), integerFormat);
if (fieldTypes[col] == double.class || fieldTypes[col] == Double.class)
return new jxl.write.Number(col, row, value == null ? 0 : ((Double) value).doubleValue(), floatFormat);
if (fieldTypes[col] == float.class || fieldTypes[col] == Float.class)
return new jxl.write.Number(col, row, value == null ? 0 : ((Float) value).floatValue(), floatFormat);
if (fieldTypes[col] == BigDecimal.class)
return new jxl.write.Number(col, row, value == null ? 0 : ((BigDecimal) value).doubleValue(), floatFormat);
if (fieldTypes[col] == Timestamp.class || fieldTypes[col] == Date.class)
return new jxl.write.DateTime(col, row, value == null ? new Date() : (Date) value, dateFormat);
return null;
}
}
posted @
2007-08-10 14:18 华梦行 阅读(230) |
评论 (0) |
编辑 收藏
var oOpener = dialogArguments ;
oOpener.szOldPassword = document.all.OldPassword.value ;
oOpener.szNewPassword = document.all.NewPassword.value ;
oOpener.bIsEditPwd = true ;
openDialog('UserModifyPwd.jsp?TimeID=' + Math.random(),window,300,180) ;
if (bIsEditPwd == true){
document.Form1.OldPassword.value = szOldPassword ;
document.Form1.NewPassword.value = szNewPassword ;
top.topFrame.saveURL('../Configure/UserConfigure.jsp?AutoShow=Yes&TimeID=' + Math.random()) ;
document.Form1.submit() ;
}
posted @
2007-08-01 16:26 华梦行 阅读(581) |
评论 (0) |
编辑 收藏
select * from col , user_tab_cols
posted @
2007-07-31 11:39 华梦行 阅读(87) |
评论 (0) |
编辑 收藏
D:\aa>keytool -genkey -v -alias JoeUserKey -keyalg RSA
输入keystore密码: huamengxing
您的名字与姓氏是什么?
[Unknown]: Joe usr
您的组织单位名称是什么?
[Unknown]: security
您的组织名称是什么?
[Unknown]: commmm,Inc
您所在的城市或区域名称是什么?
[Unknown]: fsdfs
您所在的州或省份名称是什么?
[Unknown]: fsdfsd
该单位的两字母国家代码是什么
[Unknown]: cn
CN=Joe usr, OU=security, O="commmm,Inc", L=fsdfs, ST=fsdfsd, C=cn 正确吗?
[否]: y
创建1,024比特RSA键值对及针对CN=Joe usr, OU=security, O="commmm,Inc", L=fsdfs, ST
=fsdfsd, C=cn的自我签署的认证 (MD5WithRSA)
:
输入<JoeUserKey>的主密码
(如果和 keystore 密码相同,按回车):
[正在存储 C:\Documents and Settings\ljl\.keystore]
D:\aa>keytool -list -v -genkey -alias JooUserKey
输入keystore密码: huamengxing
您的名字与姓氏是什么?
[Unknown]: Joe usr
您的组织单位名称是什么?
[Unknown]: security
您的组织名称是什么?
[Unknown]: commmm,Inc
您所在的城市或区域名称是什么?
[Unknown]: fadfs
您所在的州或省份名称是什么?
[Unknown]: fsdfsd
该单位的两字母国家代码是什么
[Unknown]: cn
CN=Joe usr, OU=security, O="commmm,Inc", L=fadfs, ST=fsdfsd, C=cn 正确吗?
[否]: y
创建1,024比特DSA键值对及针对CN=Joe usr, OU=security, O="commmm,Inc", L=fadfs, ST
=fsdfsd, C=cn的自我签署的认证 (SHA1WithDSA)
:
输入<JooUserKey>的主密码
(如果和 keystore 密码相同,按回车):
[正在存储 C:\Documents and Settings\ljl\.keystore]
D:\aa>keytool -list -v -alias JooUserKey
输入keystore密码: huamengxing
别名名称: JooUserKey
创建日期: 2007-7-30
输入类型:KeyEntry
认证链长度: 1
认证 [1]:
Owner: CN=Joe usr, OU=security, O="commmm,Inc", L=fadfs, ST=fsdfsd, C=cn
发照者: CN=Joe usr, OU=security, O="commmm,Inc", L=fadfs, ST=fsdfsd, C=cn
序号: 46ad82e0
有效期间: Mon Jul 30 14:19:12 CST 2007 至: Sun Oct 28 14:19:12 CST 2007
认证指纹:
MD5: 88:F5:21:21:2C:65:03:84:60:12:65:55:39:D3:A0:1E
SHA1: 37:B6:87:9F:C4:EA:E4:50:9A:F4:00:B3:41:58:C8:F0:10:5E:44:8E
D:\aa>
D:\>keytool.exe -genkey -alias Tomcat -keyalg RSA -storepass bigsecret -keypass bigsecret -dname "cn=localhost"
执行完该命令后,就会在HOME目录下生成一个.keystore文件。下面是各种切换命令的含义:
· genkey:告诉keytool应用程序生成新的公钥/私钥对。
· alias:用于引用密钥的名称。记住,.keystore文件可包含多个密钥。
· Keyalg:使用RSA算法生成公钥/私钥对。
· Storepass:访问.keystore文件所需的口令。
· Keypass:管理密钥所需的口令。
· dname:该值非常重要。.我使用了localhost,因为该示例被设计为本地运行。如果一个Web应用程序被注册为http://www.myserver.com,那么该值就必须是www.myserver.com。如果名称不匹配,证书就会自动被拒绝。
一旦keytool应用程序创建了一个新的公钥/私钥对,它就自动自签名该密钥。我们刚刚生成了自己的自签名证书,它可用于HTTPS通信。只需提取出自签名公钥。后面我将展示如何做。
posted @
2007-07-30 14:24 华梦行 阅读(1279) |
评论 (0) |
编辑 收藏
public void close()
{
try
{
if(rs!=null) rs.close();
if(st!=null) st.close();
if(cn!=null) cn.close();
}
catch(SQLException _ex)
{
try
{
if(rs != null) rs.close();
}
catch(SQLException _ex2)
{
try
{
if(st != null) st.close();
}
catch(SQLException _ex3) {
}
try
{
if(cn != null) cn.close();
}
catch(SQLException _ex3) {
}
}
try
{
if(st != null) st.close();
}
catch(SQLException _ex2)
{
try
{
if(cn != null) cn.close();
}
catch(SQLException _ex3) {
}
}
try
{
if(cn != null) cn.close();
}
catch(SQLException _ex2) {
}
}
finally
{
try
{
// if(rs!=null) rs.close();
if(st!=null) st.close();
if(cn!=null) cn.close();
}
catch(Exception e)
{
//System.out.println(e.toString());
}
}
}
posted @
2007-07-27 13:56 华梦行 阅读(90) |
评论 (0) |
编辑 收藏
select NVL(b.Name, ' ') AS spec, ' ' as packs,
'' as Quant,
'' as Price,
NVL(a.feeamount,0) as amount, ' ' as cpbh,' ' as cpname, ' ' as jidw
from ITM_Documentfee a left join
sys_datadictionary b on b.id=a.feeid
union
select
NVL(b.Spec, ' ') AS spec,
NVL(b.field1,' ') as packs,
case Quant
when 0 then
' '
when null then
' '
else
to_char(Quant)
end as Quant
,
case Price
when 0 then
' '
when null then
' '
else
to_char(Price)
end as Price
,
NVL(b.Amount, 0) AS amount,
c.SerialNumber as cpbh,NVL(c.EnName, ' ') AS cpname,
NVL(t.Symbol, ' ') AS jidw
from ITM_SalesCommodity b
left join CRM_Commodity c ON c.TypeID = b.CommodityTypeID
LEFT OUTER JOIN BSE_MeasureStyle t ON b.QuantUnitID = t.ID
select ISNULL(b.Name, ' ') AS spec, ' ' as packs,
'' as Quant,
'' as Price,
isnull(a.feeamount,0) as amount, ' ' as cpbh,' ' as cpname, ' ' as jidw
from ITM_Documentfee a left join
sys_datadictionary b on b.id=a.feeid
union
select
ISNULL(b.Spec, ' ') AS spec,
isnull(b.field1,' ') as packs,
Quant =
case
when Quant>0 then
CAST( Quant AS varchar(20))
else ''
end
,
Price =
case
when Price>0 then
CAST( Price AS varchar(20))
else ''
end
,
ISNULL(b.Amount, 0) AS amount,
c.SerialNumber as cpbh,ISNULL(c.EnName, ' ') AS cpname,
ISNULL(t.Symbol, ' ') AS jidw
from ITM_SalesCommodity b
left join CRM_Commodity c ON c.TypeID = b.CommodityTypeID
LEFT OUTER JOIN BSE_MeasureStyle t ON b.QuantUnitID = t.ID
posted @
2007-07-27 13:44 华梦行 阅读(95) |
评论 (0) |
编辑 收藏
using System;
using System.Data;
using System.Data.SqlClient;
namespace com.hua..li
{
/// <summary>
/// 数据库操作
/// </summary>
public class pathDB:pathPage
{
override protected void OnInit(EventArgs e)
{
pathInit();
base.OnInit(e);
}
protected void pathInit()
{
this.ConnectDb();
}
protected void ConnectDb()
{
if(doh == null)
{
System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["connString"]);
doh = new com.path.SqlDbOperHandler(conn);
}
}
}
}
using System;
namespace com.hua.li
{
/// <summary>
/// 表示数据库连接类型。
/// </summary>
public enum DatabaseType:byte{SqlServer,OleDb};
/// <summary>
/// DbOperHandler 的摘要说明。
/// </summary>
public abstract class DbOperHandler
{
/// <summary>
/// 析构函数,释放申请的资源。
/// </summary>
~DbOperHandler()
{
conn.Close();
}
/// <summary>
/// 表示数据库连接的类型,目前支持SqlServer和OLEDB
/// </summary>
protected DatabaseType dbType=DatabaseType.OleDb;
/// <summary>
/// 返回当前使用的数据库连接对象。
/// </summary>
/// <returns></returns>
public System.Data.IDbConnection GetConnection()
{
return conn;
}
/// <summary>
/// 条件表达式,用于在数据库操作时筛选记录,通常用于仅需指定表名称和某列名称的操作,如GetValue(),Delete()等,支持查询参数,由AddConditionParameters指定。。
/// </summary>
public string ConditionExpress=string.Empty;
/// <summary>
/// 当前的SQL语句。
/// </summary>
public string SqlCmd=string.Empty;
/// <summary>
/// 当前操作所涉及的数据表名称。
/// </summary>
protected string tableName=string.Empty;
/// <summary>
/// 当前操作所设计的字段名称。
/// </summary>
protected string fieldName=string.Empty;
/// <summary>
/// 当前所使用的数据库连接。
/// </summary>
protected System.Data.IDbConnection conn;
/// <summary>
/// 当前所使用的命令对象。
/// </summary>
protected System.Data.IDbCommand cmd;
/// <summary>
/// 当前所使用的数据库适配器。
/// </summary>
protected System.Data.IDbDataAdapter da;
/// <summary>
/// 用于存储字段/值配对。
/// </summary>
protected System.Collections.ArrayList alFieldItems=new System.Collections.ArrayList(10);
/// <summary>
/// 用于存储SQL语句中的查询参数。
/// </summary>
protected System.Collections.ArrayList alSqlCmdParameters=new System.Collections.ArrayList(5);
/// <summary>
/// 用于存储条件表达式中的查询参数。
/// </summary>
protected System.Collections.ArrayList alConditionParameters=new System.Collections.ArrayList(5);
/// <summary>
/// 重值该对象,使之恢复到构造时的状态。
/// </summary>
public void Reset()
{
this.alFieldItems.Clear();
this.alSqlCmdParameters.Clear();
this.alConditionParameters.Clear();
this.ConditionExpress=string.Empty;
this.SqlCmd=string.Empty;
this.cmd.Parameters.Clear();
this.cmd.CommandText=string.Empty;
}
/// <summary>
/// 添加一个字段/值对到数组中。
/// </summary>
/// <param name="_fieldName">字段名称。</param>
/// <param name="_fieldValue">字段值。</param>
public void AddFieldItem(string _fieldName,object _fieldValue)
{
for(int i=0;i<this.alFieldItems.Count;i++)
{
if(((DbKeyItem)this.alFieldItems[i]).fieldName==_fieldName)
{
throw new ArgumentException("The field name has existed!");
}
}
this.alFieldItems.Add(new DbKeyItem(_fieldName,_fieldValue));
}
/// <summary>
/// 添加条件表达式中的查询参数到数组中。注意:当数据库连接为SqlServer时,参数名称必须和SQL语句匹配。其它则只需保持添加顺序一致,名称无需匹配。
/// </summary>
/// <param name="_conditionName">条件名称。</param>
/// <param name="_conditionValue">条件值。</param>
public void AddConditionParameter(string _conditionName,object _conditionValue)
{
for(int i=0;i<this.alConditionParameters.Count;i++)
{
if(((DbKeyItem)this.alConditionParameters[i]).fieldName==_conditionName)
{
throw new ArgumentException("The condition name has existed!");
}
}
this.alConditionParameters.Add(new DbKeyItem(_conditionName,_conditionValue));
}
/// <summary>
/// 添加SQL语句中的查询参数到数组中。注意:当数据库连接为SqlServer时,参数名称必须和SQL语句匹配。其它则只需保持添加顺序一致,名称无需匹配。
/// </summary>
/// <param name="_paraName">参数名称。</param>
/// <param name="_paraValue">参数值。</param>
public void AddSqlCmdParameters(string _paraName,object _paraValue)
{
for(int i=0;i<this.alSqlCmdParameters.Count;i++)
{
if(((DbKeyItem)this.alSqlCmdParameters[i]).fieldName==_paraName)
{
throw new ArgumentException("The sqlcmd parameter name has existed!");
}
}
this.alSqlCmdParameters.Add(new DbKeyItem(_paraName,_paraValue));
}
public bool Exist(string tableName)
{
return this.GetValue(tableName,"count(*)").ToString()!="0";
}
/// <summary>
/// 抽象函数。用于产生Command对象所需的参数。
/// </summary>
protected abstract void GenParameters();
/// <summary>
/// 根据当前alFieldItem数组中存储的字段/值向指定表中添加一条数据。在该表无触发器的情况下返回添加数据所获得的自动增长id值。
/// </summary>
/// <param name="_tableName">要插入数据的表名称。</param>
/// <returns>返回本数据连接上产生的最后一个自动增长id值。</returns>
public int Insert(string _tableName)
{
this.tableName=_tableName;
this.fieldName=string.Empty;
this.SqlCmd="insert into "+this.tableName+"(";
string tempValues=" values(";
for(int i=0;i<this.alFieldItems.Count-1;i++)
{
this.SqlCmd+=((DbKeyItem)alFieldItems[i]).fieldName;
this.SqlCmd+=",";
tempValues+="@para";
tempValues+=i.ToString();
tempValues+=",";
}
this.SqlCmd+=((DbKeyItem)alFieldItems[alFieldItems.Count-1]).fieldName;
this.SqlCmd+=") ";
tempValues+="@para";
tempValues+=(alFieldItems.Count-1).ToString();
tempValues+=")";
this.SqlCmd+=tempValues;
this.cmd.CommandText=this.SqlCmd;
this.GenParameters();
cmd.ExecuteNonQuery();
cmd.CommandText="select @@identity as id";
int autoId=Convert.ToInt32(cmd.ExecuteScalar());
return autoId;
}
/// <summary>
/// 根据当前alFieldItem数组中存储的字段/值和条件表达式所指定的条件来更新数据库中的记录,返回所影响的行数。
/// </summary>
/// <param name="_tableName">要更新的数据表名称。</param>
/// <returns>返回此次操作所影响的数据行数。</returns>
public int Update(string _tableName)
{
this.tableName=_tableName;
this.fieldName=string.Empty;
this.SqlCmd="update "+this.tableName+" set ";
for(int i=0;i<this.alFieldItems.Count-1;i++)
{
this.SqlCmd+=((DbKeyItem)alFieldItems[i]).fieldName;
this.SqlCmd+="=";
this.SqlCmd+="@para";
this.SqlCmd+=i.ToString();
this.SqlCmd+=",";
}
this.SqlCmd+=((DbKeyItem)alFieldItems[alFieldItems.Count-1]).fieldName;
this.SqlCmd+="=";
this.SqlCmd+="@para";
this.SqlCmd+=(alFieldItems.Count-1).ToString();
if(this.ConditionExpress!=string.Empty)
{
this.SqlCmd=this.SqlCmd+" where "+this.ConditionExpress;
}
this.cmd.CommandText=this.SqlCmd;
this.GenParameters();
int effectedLines=this.cmd.ExecuteNonQuery();
return effectedLines;
}
/// <summary>
/// 执行SqlCmd中的SQL语句,参数由AddSqlCmdParameters指定,与ConditionExpress无关。
/// </summary>
/// <returns>返回此次操作所影响的数据行数。</returns>
public int ExecuteSqlNonQuery()
{
this.cmd.CommandText=this.SqlCmd;
this.GenParameters();
return cmd.ExecuteNonQuery();
}
/// <summary>
/// 获取指定表,指定列,指定条件的第一个符合条件的值。
/// </summary>
/// <param name="_tableName">表名称。</param>
/// <param name="_fieldName">字段名称。</param>
/// <returns>获取的值。如果为空则返回null。</returns>
public object GetValue(string _tableName,string _fieldName)
{
this.tableName=_tableName;
this.fieldName=_fieldName;
this.SqlCmd="select "+this.fieldName+" from "+this.tableName;
if(this.ConditionExpress!=string.Empty)
{
this.SqlCmd=this.SqlCmd+" where "+this.ConditionExpress;
}
this.cmd.CommandText=this.SqlCmd;
this.GenParameters();
return cmd.ExecuteScalar();
}
/// <summary>
/// 根据当前指定的SqlCmd获取DataTable。如果ConditionExpress不为空则会将其清空,所以条件表达式需要包含在SqlCmd中。
/// </summary>
/// <returns>返回查询结果DataTable。</returns>
public System.Data.DataTable GetDataTable()
{
System.Data.DataSet ds=this.GetDataSet();
return ds.Tables[0];
}
/// <summary>
/// 根据当前指定的SqlCmd获取DataSet。如果ConditionExpress不为空则会将其清空,所以条件表达式需要包含在SqlCmd中。
/// </summary>
/// <returns>返回查询结果DataSet。</returns>
public System.Data.DataSet GetDataSet()
{
this.alConditionParameters.Clear();
this.ConditionExpress=string.Empty;
this.cmd.CommandText=this.SqlCmd;
this.GenParameters();
System.Data.DataSet ds=new System.Data.DataSet();
this.da.SelectCommand=this.cmd;
this.da.Fill(ds);
return ds;
}
/// <summary>
/// 对指定表,指定字段执行加一计数,返回计数后的值。条件由ConditionExpress指定。
/// </summary>
/// <param name="_tableName">表名称。</param>
/// <param name="_fieldName">字段名称。</param>
/// <returns>返回计数后的值。</returns>
public int Count(string _tableName,string _fieldName)
{
this.tableName=_tableName;
this.fieldName=_fieldName;
int count=Convert.ToInt32(this.GetValue(this.tableName,this.fieldName));
count++;
this.cmd.Parameters.Clear();
this.cmd.CommandText=string.Empty;
this.AddFieldItem(_fieldName,count);
this.Update(this.tableName);
return count;
}
/// <summary>
/// 对指定表,指定字段执行减一计数,返回计数后的值。条件由ConditionExpress指定。
/// </summary>
/// <param name="_tableName">表名称。</param>
/// <param name="_fieldName">字段名称。</param>
/// <returns>返回计数后的值。</returns>
public int Substract(string _tableName,string _fieldName)
{
this.tableName=_tableName;
this.fieldName=_fieldName;
int count=Convert.ToInt32(this.GetValue(this.tableName,this.fieldName));
if(count>0)count--;
this.cmd.Parameters.Clear();
this.cmd.CommandText=string.Empty;
this.AddFieldItem(_fieldName,count);
this.Update(this.tableName);
return count;
}
/// <summary>
/// 根据ConditionExpress指定的条件在指定表中删除记录。返回删除的记录数。
/// </summary>
/// <param name="_tableName">指定的表名称。</param>
/// <returns>返回删除的记录数。</returns>
public int Delete(string _tableName)
{
this.tableName=_tableName;
this.SqlCmd="delete from "+this.tableName;
if(this.ConditionExpress!=string.Empty)
{
this.SqlCmd=this.SqlCmd+" where "+this.ConditionExpress;
}
this.cmd.CommandText=this.SqlCmd;
this.GenParameters();
return cmd.ExecuteNonQuery();
}
/// <summary>
/// 函数sendMsg需要 __Receive接受者 如果是系统则为 admin 否则为手机号码
/// </summary>
/// <param name="_PHONE">手机号码</param>
/// <param name="_KeyWorld">关键字</param>
/// <param name="_INFO">信息的基本内容</param>
/// <param name="_Receive">接受者</param>
/// <returns></returns>
public bool SendMsg(string _PHONE, string _KeyWorld, string _INFO, string _Receive)
{
bool SendOk;
if (_PHONE != null || _KeyWorld != null)
{
this.Reset();
this.AddFieldItem("PHONE", _PHONE);
this.AddFieldItem("KeyWorld", _KeyWorld);
this.AddFieldItem("INFO", _INFO);
this.AddFieldItem("Receive", _Receive);
this.Insert("smsRawRecv").ToString();
SendOk = true;
}
else
{
SendOk = false;
}
return SendOk;
}
/// <summary>
///
/// </summary>
/// <param name="_PHONE"></param>
/// <param name="_KeyWorld"></param>
/// <param name="_INFO"></param>
/// <param name="_Receive"></param>
/// <returns></returns>
//public bool Received(string _PHONE, string _KeyWorld, string _INFO, string _Receive)
//{
// bool Received, SendOk;
// if (SendOk)
// {
// if (_PHONE != null || _KeyWorld != null)
// {
// this.Reset();
// this.AddFieldItem("PHONE", _PHONE);
// this.AddFieldItem("KeyWorld", _KeyWorld);
// this.AddFieldItem("INFO", _INFO);
// this.AddFieldItem("Receive", _Receive);
// this.Insert("smsSended").ToString();
// Received = true;
// }
// else
// {
// Received = false;
// }
// }
// else
// {
// Received = false;
// }
//}
/// <summary>
/// 审核函数。将指定表,指定字段的值进行翻转,如:1->0或0->1。条件由ConditionExpress指定。
/// </summary>
/// <param name="_tableName">表名称。</param>
/// <param name="_fieldName">字段名称。</param>
/// <returns>返回影响的行数。</returns>
public int Audit(string _tableName,string _fieldName)
{
this.tableName=_tableName;
this.fieldName=_fieldName;
this.SqlCmd="update "+this.tableName+" set "+this.fieldName+"=1-"+this.fieldName;
if(this.ConditionExpress!=string.Empty)
{
this.SqlCmd=this.SqlCmd+" where "+this.ConditionExpress;
}
this.cmd.CommandText=this.SqlCmd;
this.GenParameters();
return cmd.ExecuteNonQuery();
}
/// <summary>
/// 释放资源
/// </summary>
public void Dispose()
{
conn.Close();
}
}
/// <summary>
/// 数据表中的字段属性,包括字段名,字段值。
/// 常用于保存要提交的数据。
/// </summary>
public class DbKeyItem
{
/// <summary>
/// 构造函数。
/// </summary>
/// <param name="_fieldName">字段名称。</param>
/// <param name="_fieldValue">字段值。</param>
public DbKeyItem(string _fieldName,object _fieldValue)
{
this.fieldName=_fieldName;
this.fieldValue=_fieldValue.ToString();
}
/// <summary>
/// 字段名称。
/// </summary>
public string fieldName;
/// <summary>
/// 字段值。
/// </summary>
public string fieldValue;
}
}
posted @
2007-07-27 11:09 华梦行 阅读(332) |
评论 (0) |
编辑 收藏
用了这么久的PHP,今天才知道原来PHP对函数名、类名大小写不敏感。我一直都以为是跟变量名一样大小写敏感的。爆汗一下!!!,今天才发现PHP原来对函数名类名大小写不敏感
NULL
类型只有一个值,就是大小写敏感的关键字
NULL
posted @
2007-07-25 16:10 华梦行 阅读(278) |
评论 (0) |
编辑 收藏
端口冲突问题,开机后便宣布某个端口归某个应用程序所有
posted @
2007-07-25 15:55 华梦行 阅读(92) |
评论 (0) |
编辑 收藏
1下载 apatche http server,下php 安装程序,
2. 设置环境变量, class pass php安装路径
3. 设置apatche的根路径 doc_root ="C:\Program Files\Apache Software Foundation\Apache2.2\htdocs"
posted @
2007-07-25 15:54 华梦行 阅读(96) |
评论 (0) |
编辑 收藏