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
慢,因為它是同步的。
Boolean.parseBoolean("Strrrr");?? false
只有String 在忽略大小寫的情況小“true”才會返回true
/*
?* 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);
??? }
???
}
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-configuration> ??? <session-factory> ??????? <!-- Database connection settings --> ??????? <!-- SQL dialect --> ??????? <!-- Enable Hibernate's automatic session context management --> ??????? <!-- Disable the second-level cache? --> ??????? <!-- Echo all executed SQL to stdout --> </hibernate-configuration> ? Session session = HibernateUtil.getSession(); package path.system.manager; import java.io.*; import jxl.*; import path.system.manager.HibernateUtil; /** D:\aa>keytool -genkey -v -alias JoeUserKey -keyalg RSA 創建1,024比特RSA鍵值對及針對CN=Joe usr, OU=security, O="commmm,Inc", L=fsdfs, ST D:\aa>keytool -list -v -genkey -alias JooUserKey 創建1,024比特DSA鍵值對及針對CN=Joe usr, OU=security, O="commmm,Inc", L=fadfs, ST D:\aa>keytool -list -v? -alias JooUserKey D:\aa> 執行完該命令后,就會在HOME目錄下生成一個.keystore文件。下面是各種切換命令的含義: · genkey:告訴keytool應用程序生成新的公鑰/私鑰對。 public void close() ??????????? try ??? } select NVL(b.Name, ' ') AS spec, ' ' as packs, ?NVL(a.feeamount,0) as amount, ' ' as cpbh,' ' as cpname, ' ' as jidw union ?isnull(a.feeamount,0) as amount, ' ' as cpbh,' ' as cpname, ' ' as jidw union using System; namespace com.hua..li ??override protected void OnInit(EventArgs e) ??protected void pathInit() ??protected void ConnectDb() namespace com.hua.li ?? ????for(int i=0;i<this.alFieldItems.Count;i++) ???/// <summary> ???public bool Exist(string tableName) ?????tempValues+="@para"; ?????tempValues+=","; ????tempValues+="@para"; ????tempValues+=")"; ???/// <summary> ?????this.SqlCmd+="@para"; ?????this.SqlCmd+=","; ????this.SqlCmd+="@para";
???/// <summary> ???/// <summary> ???/// <summary> ???/// <summary> ??/// <summary> 1下載 apatche http server,下php 安裝程序,?
??????? "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
??????? "
??????? <property? name="connection.datasource">java:comp/env/jdbc/PathPlat</property>?
??????? <!--<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>-->
??????? <property name="dialect">org.hibernate.dialect.OracleDialect</property>
??????? <property name="current_session_context_class">thread</property>
??????? <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
??????? <property name="show_sql">false</property>
?<mapping resource="/wms/entity/WmsAdjustStoreCmdt.hbm.xml"/>
??????? <mapping resource="/wms/entity/WmsStorage.hbm.xml"/>
??
??? </session-factory>
?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;?
document.getElementById("ffff").readOnly=true;
?readOnly? O必須大寫
??????????? 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.
?*/
import java.util.List;
import java.util.Date;
import java.sql.Timestamp;
import java.lang.reflect.*;
import java.math.BigDecimal;
import jxl.write.*;
import org.hibernate.Session;
import org.hibernate.Query;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
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;
??? }
???
}
??????
?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() ;
?}
select * from col , user_tab_cols??
輸入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
=fsdfsd, C=cn的自我簽署的認證 (MD5WithRSA)
??????? :
輸入<JoeUserKey>的主密碼
??????? (如果和 keystore 密碼相同,按回車):
[正在存儲 C:\Documents and Settings\ljl\.keystore]
輸入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
=fsdfsd, C=cn的自我簽署的認證 (SHA1WithDSA)
??????? :
輸入<JooUserKey>的主密碼
??????? (如果和 keystore 密碼相同,按回車):
[正在存儲 C:\Documents and Settings\ljl\.keystore]
輸入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:\>keytool.exe -genkey -alias Tomcat -keyalg RSA -storepass bigsecret -keypass bigsecret -dname "cn=localhost"
· alias:用于引用密鑰的名稱。記住,.keystore文件可包含多個密鑰。
· Keyalg:使用RSA算法生成公鑰/私鑰對。
· Storepass:訪問.keystore文件所需的口令。
· Keypass:管理密鑰所需的口令。
· dname:該值非常重要。.我使用了localhost,因為該示例被設計為本地運行。如果一個Web應用程序被注冊為http://www.myserver.com,那么該值就必須是www.myserver.com。如果名稱不匹配,證書就會自動被拒絕。
一旦keytool應用程序創建了一個新的公鑰/私鑰對,它就自動自簽名該密鑰。我們剛剛生成了自己的自簽名證書,它可用于HTTPS通信。只需提取出自簽名公鑰。后面我將展示如何做。
??? {
??????? 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) {
??????????????? }
??????????? }
??????????? {
??????????????? 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());
????????? }
??????? }
'' as Quant,
'' as Price,
from ITM_Documentfee a? left join
sys_datadictionary b on b.id=a.feeid????
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,
from ITM_Documentfee a? left join
sys_datadictionary b on b.id=a.feeid????
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
using System.Data;
using System.Data.SqlClient;
{
?/// <summary>
?/// 數據庫操作
?/// </summary>
?public class pathDB:pathPage
?{
??{
???pathInit();
???base.OnInit(e);
??}
??{
???this.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;
?{
??/// <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)
???{
????{
?????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));
???}
???/// 添加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));
???}
???{
????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+=i.ToString();
????}
????this.SqlCmd+=((DbKeyItem)alFieldItems[alFieldItems.Count-1]).fieldName;
????this.SqlCmd+=") ";
????tempValues+=(alFieldItems.Count-1).ToString();
????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;
???}
???/// 根據當前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+=i.ToString();
????}
????this.SqlCmd+=((DbKeyItem)alFieldItems[alFieldItems.Count-1]).fieldName;
????this.SqlCmd+="=";
????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;
???}
???/// 執行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;
???}
???/// 對指定表,指定字段執行減一計數,返回計數后的值。條件由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;
???}
???/// 根據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>
???public void Dispose()
???{
????conn.Close();
???}
??
??}
??/// 數據表中的字段屬性,包括字段名,字段值。
??/// 常用于保存要提交的數據。
??/// </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;
??}
?}
NULL
類型只有一個值,就是大小寫敏感的關鍵字 NULL
端口沖突問題,開機后便宣布某個端口歸某個應用程序所有
2. 設置環境變量, class pass? php安裝路徑
3. 設置apatche的根路徑 doc_root ="C:\Program Files\Apache Software Foundation\Apache2.2\htdocs"