锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲一区二区三区首页,国产精品亚洲一区二区在线观看,亚洲视频国产视频http://m.tkk7.com/Vincent-chenxj/zh-cnMon, 12 May 2025 16:38:18 GMTMon, 12 May 2025 16:38:18 GMT60C# Sample code to talk to a printer using SNMP to get its status. http://m.tkk7.com/Vincent-chenxj/archive/2009/06/18/283093.htmlVincent-chenVincent-chenThu, 18 Jun 2009 09:24:00 GMThttp://m.tkk7.com/Vincent-chenxj/archive/2009/06/18/283093.htmlhttp://m.tkk7.com/Vincent-chenxj/comments/283093.htmlhttp://m.tkk7.com/Vincent-chenxj/archive/2009/06/18/283093.html#Feedback2http://m.tkk7.com/Vincent-chenxj/comments/commentRss/283093.htmlhttp://m.tkk7.com/Vincent-chenxj/services/trackbacks/283093.html

The following code will allow you to talk to a printer (running on a specific IP Address) to query its current status.

OLEPRNLib is a COM object that appears to be installed on XP and greater machines.

On my machine I made a reference on the COM tab of the Add Reference dialog to “oleprn 1.0 Type Library“ which lived in “c:\Windows\System32\oleprn.dll

using System;
using OLEPRNLib;
namespace PrinterStatus
{
/// 
 /// Summary description for Class1.
 /// 
 class Class1
{
/// 
  /// The main entry point for the application.
  /// 
  [STAThread]
static void Main(string[] args)
{
string[] ErrorMessageText = new string[8];
ErrorMessageText[0] = "service requested";
ErrorMessageText[1] = "offline";
ErrorMessageText[2] = "paper jammed";
ErrorMessageText[3] = "door open";
ErrorMessageText[4] = "no toner";
ErrorMessageText[5] = "toner low";
ErrorMessageText[6] = "out of paper";
ErrorMessageText[7] = "low paper";
int DeviceID = 1;
int Retries = 1;
int TimeoutInMS = 2000;
string CommunityString = "public";
string IPAddressOfPrinter = "10.3.0.93";
// Create instance of COM object
   OLEPRNLib.SNMP snmp = new OLEPRNLib.SNMP();
// Open the SNMP connect to the printer
   snmp.Open(IPAddressOfPrinter, CommunityString, Retries, TimeoutInMS);
// The actual Warning/Error bits
   uint WarningErrorBits = snmp.GetAsByte(String.Format("25.3.5.1.2.{0}", DeviceID));
// The actual Status
   uint StatusResult = snmp.GetAsByte(String.Format("25.3.2.1.5.{0}", DeviceID));
// uint Result2 = snmp.GetAsByte(String.Format("25.3.5.1.1.{0}", DeviceID));

string Result1Str = "";
switch (StatusResult)
{
case 2 : Result1Str = "OK";
break;
case 3 : Result1Str = "Warning: ";
break;
case 4 : Result1Str = "Being Tested: ";
break;
case 5 : Result1Str = "Unavailable for any use: ";
break;
default : Result1Str = "Unknown Status Code : "+StatusResult;
break;
}
string Str = "";
if ((StatusResult == 3 || StatusResult == 5))
{
int Mask = 1;
int NumMsg = 0;
for (int i=0; i< 8; i++)
{
if ((WarningErrorBits & Mask) == Mask)
{
if (Str.Length > 0)
Str += ", ";
Str += ErrorMessageText[i];
NumMsg = NumMsg + 1;
}
Mask = Mask * 2;
}
}
Console.WriteLine(Result1Str + Str);
}
}
}
posted on Monday, August 08, 2005 8:13 PM | Filed Under [ c# ]

Comments


# re: C# Sample code to talk to a printer using SNMP to get its status.

Gravatar
Hello.
I have been talked to a print by this code.
But I couldn't talk to Zebra Barcode Printer ( 140 Xi III Plus Model ).

I catched Ready Status and Out of Paper Error, but another status, for example, Printing(Running) and OffLine(Pause) status.

How can I know these status?
Posted by Park Jung Sup on 6/20/2007 4:25 PM

# re: C# Sample code to talk to a printer using SNMP to get its status.

Gravatar
Can you explain me what do "25.3.5.1.2.{0}" mean and what do "25.3.5.1.5.{0}"

is there any other code like this. if so can me provide the link so that i can know more about SNMP and try to handle/get status information the devices from remote location
Posted by theertendra on 8/29/2007 11:08 PM

# re: C# Sample code to talk to a printer using SNMP to get its status.


The codes that you see are called an OID and basically companies can obtain a private OID. see http://www.alvestrand.no/objectid/

There are common OID SNMP identifiers and the ones I was using in the article

The full OID for hrPrinterDetectedErrorState

.iso.org.dod.internet.mgmt.mib-2.host.hrDevice.hrPrinterTable.hrPrinterEntry.hrPrinterDetectedErrorState

or simply .1.3.6.1.2.1.25.3.5.1.2

This object represents any error conditions detected by the printer. The error conditions are encoded as bits in an octet string, with the following

definitions:
Condition Bit #
lowPaper 0
noPaper 1
lowToner 2
noToner 3
doorOpen 4
jammed 5
offline 6
serviceRequested 7
inputTrayMissing 8
outputTrayMissing 9
markerSupplyMissing 10
outputNearFull 11
outputFull 12
inputTrayEmpty 13
overduePreventMaint 14

Bits are numbered starting with the most significant bit of the first byte being bit 0, the least significant bit of the first byte being bit 7, the
most significant bit of the second byte being bit 8, and so on. A one bit encodes that the condition was detected, while a zero bit encodes that the condition was not detected.

This object is useful for alerting an operator to specific warning or error conditions that may occur, especially those requiring human intervention.

The best way to see what is around is to look at a MIB Browser
http://www.ireasoning.com/mibbrowser.shtml

If you download the tool above there is a free version and you would then load the Printer-MIB.MIB to get information like above.
Posted by Chris Crowe on 8/30/2007 4:44 AM

# re: C# Sample code to talk to a printer using SNMP to get its status.

Gravatar
My SNMP program is the simple program and write in the C# language. But I faced the problem that I need to type the IP address for my slave before I can get the MIB of my slave, how I can detect my slave's IP address directly without type the IP address? Can you give me some guidelines? Furthermore, I need some coding that write in C# that can show the status for my slaves, such as my slave is on or off. I hope that you can give me some guidelines. Thanks.
Posted by jelly on 1/12/2008 4:43 AM

# re: C# Sample code to talk to a printer using SNMP to get its status.


Hi All,

Can anybody can guide me how can i get all the printer names which are all attached in a Network ?
Posted by SEN on 5/2/2008 6:46 PM

# re: C# Sample code to talk to a printer using SNMP to get its status.

Gravatar
nice peace of code, thanks for sharing. unfortunately oleprn.dll isn't documented anywhere...but nevertheless i think i can use it for simple snmp queries.

seems to me as if you forgot to
snmp.close();
after querying.
Posted by andre on 7/3/2008 11:50 PM

# re: C# Sample code to talk to a printer using SNMP to get its status.

Gravatar
hi ,
I need to know whether the printer(dymo label printer) status active or not which was installed on the network (192.168.1.18\dymolabel shared) from the other machine.
the above example doesent work for me as i cant get the OID for the dymo label printer.
Can any one help me how to do the above requirement please
Posted by srinivas on 8/8/2008 2:47 AM

# re: C# Sample code to talk to a printer using SNMP to get its status.

Gravatar
after snmp.open at the following code
uint WarningErrorBits = snmp.GetAsByte(String.Format("25.3.5.1.2.{0}", DeviceID));

I am getting error "HRESULT E_FAIL has returned from a call to a COM component"
Can any one help me why I am getting the error!!

Posted by Ramesh on 9/4/2008 12:19 AM

# re: C# Sample code to talk to a printer using SNMP to get its status.

Gravatar
>> I am getting error "HRESULT E_FAIL has returned from a call to a COM component"

I just got this one too and when pinged it the printer was down.
Make sure the printer is up.
Posted by Victor on 10/2/2008 8:14 AM

# re: java Sample code to talk to a printer using SNMP to get its status.

Gravatar
i am going to develop simulator printer,so i need to develop printer mibs for virtual printer to operate them by snmp operation like set,get and trap by specifying oids.
Posted by vinay on 2/12/2009 3:01 AM

# re: C# Sample code to talk to a printer using SNMP to get its status.

Gravatar
hello everyone,
can anybody guide me to write the code in C# to access the of various node status in LAN using SNMP protocol.If any one is interested please mail me.
Posted by Sagar Mirajkar on 3/2/2009 3:15 AM

# re: C# Sample code to talk to a printer using SNMP to get its status.


hai thnks for giving this code to get status . I need more information about Printer like
1. whether Printer is Printing or not,
2. whether it is on Or off,
3.how many copies printed.

Can u help me
Posted by XXXXXXX on 3/17/2009 10:18 PM

# re: C# Sample code to talk to a printer using SNMP to get its status.

Gravatar
hello
Is it possible to use snmp on network to get informations (counter) from shared printers ?
Posted by jd on 3/17/2009 10:37 PM

# re: C# Sample code to talk to a printer using SNMP to get its status.


ya is it possible
Posted by XXXXXXX on 3/18/2009 12:20 AM

# re: C# Sample code to talk to a printer using SNMP to get its status.


can u reply quickly? i need to develop an appliacation controlling printer pls
Posted by XXXXXXX on 3/18/2009 12:40 AM

# re: C# Sample code to talk to a printer using SNMP to get its status.

Gravatar
you said it is possible to retrieve information from a shared printer (not à network printer) but how.

for a network printer i send an smtp request to the printer's IP with oid : 1.3.6.1.2.1.43.10.2.1.4.1.1

but for a shared printer i have to send it to the computer?
Posted by jd on 3/19/2009 3:55 AM


]]>
OIDhttp://m.tkk7.com/Vincent-chenxj/archive/2009/06/18/283090.htmlVincent-chenVincent-chenThu, 18 Jun 2009 09:20:00 GMThttp://m.tkk7.com/Vincent-chenxj/archive/2009/06/18/283090.htmlhttp://m.tkk7.com/Vincent-chenxj/comments/283090.htmlhttp://m.tkk7.com/Vincent-chenxj/archive/2009/06/18/283090.html#Feedback0http://m.tkk7.com/Vincent-chenxj/comments/commentRss/283090.htmlhttp://m.tkk7.com/Vincent-chenxj/services/trackbacks/283090.html 鏈嶅姟鍣ㄨ繕鍖呮嫭紜洏鍒╃敤鐜囥?br />


1銆佸湪windows涓婂畨瑁卻nmp錛氭帶鍒墮潰鏉?>娣誨姞/鍒犻櫎紼嬪簭->娣誨姞/鍒犻櫎windows緇勪歡->綆$悊鍜岀洃瑙嗗伐鍏?>璇︾粏淇℃伅->snmp鍗忚
2銆佽浣犱滑鍏堣鐪熶簡瑙e涔燩HP銆傚湪鏈哄櫒涓婂畨瑁匒PACHE+PHP+MYSQL鐨勮璁$幆澧冿紝騫剁啛鎮夌幆澧冦傛湁闂闅忔椂鑱旂郴鎴戙?br /> 3銆佷綘鍙互鍦ㄦ湰鏈哄畨瑁卻nmp agent 錛屼箣鍚庤鍙栨湰鏈虹殑鐩稿叧鍙傛暟銆?       

閮ㄥ垎閲嶈OID淇℃伅錛?br /> 1銆佸唴瀛樺ぇ灝?br /> 鏈嶅姟鍣ㄥ唴瀛樼殑OID鏄細.1.3.6.1.2.1.25.2.2.0錛屼笉鍚岀殑鎿嶄綔緋葷粺涔熸槸浣跨敤涓鏍風殑OID銆備絾鏄綉緇滆澶囧唴瀛樼殑OID鏍規嵁璁懼鐨勭敓浜у巶鍟嗕笉鍚屻佸瀷鍙蜂笉鍚岋紝鍏禣ID涔熸槸涓嶅悓鐨勩侰isco鐨勮礬鐢卞櫒鍜屼氦鎹㈡満閮芥槸.1.3.6.1.4.1.9.9.48.1.1.1.5.1銆傚崕涓轟氦鎹㈡満Huawei 6502銆丠uawei 3526銆丠uawei 2403鐨凮ID鏄?1.3.6.1.4.1.2011.6.1.2.1.1.2.0銆傝屽崕涓夌殑H3C E328鍜孒3C E126鐨凮ID鏄?1.3.6.1.4.1.2011.6.1.2.1.1.2.65536銆?br /> 2銆?nbsp;       鍐呭瓨鍒╃敤鐜?br /> 涓庡唴瀛樺ぇ灝忕殑OID鐩稿搴旓紝鍚勮鐩戞帶瀵硅薄鐨勫唴瀛樺埄鐢ㄧ巼鐨凮ID濡備笅錛?br /> 鏈嶅姟鍣ㄥ唴瀛樺埄鐢ㄧ巼鐨凮ID鏄?1.3.6.1.4.1.2021.4.6.0錛涘崕涓轟氦鎹㈡満鐨凮ID鏄?1.3.6.1.4.1.2011.6.1.2.1.1.3.0銆傚崕涓変氦鎹㈡満鐨凮ID鏄?1.3.6.1.4.1.2011.6.1.2.1.1.3.65536銆?br /> 3銆?nbsp;       紜洏澶у皬鍙婂埄鐢ㄧ巼
瀵逛簬鏈嶅姟鍣ㄧ殑紜洏絀洪棿鏉ヨ錛屽洜涓烘瘡涓湇鍔″櫒鐨勭‖鐩樹釜鏁板拰鐩綍鍒掑垎閮戒笉涓鏍鳳紝鎵浠ヨ鍙栧埌鐨勭洰褰曠┖闂村ぇ灝忓搴旂殑OID渚濇涓猴細.1.3.6.1.2.1.25.2.3.1.5.1 銆?1.3.6.1.2.1.25.2.3.1.5.2絳夛紝騫朵笖鍦ㄨ鍙栨瘡涓洰褰曠┖闂村ぇ灝忕殑鍚屾椂瑕佽鍙栬鐩綍鐨勫悕縐幫紙OID渚濇涓猴細.1.3.6.1.2.1.25.2.3.1.3.1銆?1.3.6.1.2.1.25.2.3.1.3.2絳夛級浣滀負璇ョ洃鎺у璞$殑鎻忚堪銆傚叧浜庣洰褰曠┖闂寸殑鍒╃敤鐜囨病鏈夌幇鎴愮殑OID錛岄渶瑕佸厛鑾峰緱鐩綍絀洪棿鐨勪嬌鐢ㄩ噺錛圤ID渚濇涓猴細.1.3.6.1.2.1.25.2.3.1.6.1銆?1.3.6.1.2.1.25.2.3.1.6.2銆佺瓑錛夛紝鐒跺悗閫氳繃浣跨敤閲忎笌絀洪棿鎬婚噺鐨勬瘮杈冨緱鍑哄埄鐢ㄧ巼銆?br /> 4銆?nbsp;       绔彛鐘舵?br /> 瀵逛簬鏈嶅姟鍣ㄦ潵璇達紝鏈夌殑鏈嶅姟鍣ㄤ負浜嗗畬鎴愬鏉傜殑鍔熻兘闇瑕侀厤緗鍧楃綉鍗★紝鍥犳涔熷氨浼氭湁澶氫釜绔彛闇瑕佺洃鎺с傚叧浜庣鍙g姸鎬佺殑OID鍒欎緷嬈′負錛?1.3.6.1.2.1.2.2.1.7.1銆?1.3.6.1.2.1.2.2.1.7.2銆?1.3.6.1.2.1.2.2.1.7.3絳夛紝闄や簡绔彛鐘舵佺郴緇熻繕闇瑕佺煡閬撹绔彛鐨勫悕縐幫紙OID渚濇涓猴細.1.3.6.1.2.1.2.2.1銆?.1銆?1.3.6.1.2.1.2.2.1.2.2銆?1.3.6.1.2.1.2.2.1.2.3絳夛級銆傚湪鑾峰彇浜ゆ崲鏈虹殑绔彛鐘舵佹椂棣栧厛鍙皢鐘舵乁P鐨勭鍙d俊鎭褰曚笅鏉ワ紝鍐嶉氳繃姣忎釜绔彛鐨勪綔鐢ㄦ潵閫夋嫨鏄惁鐪熺殑瀵瑰叾榪涜鐩戞帶銆備竴鑸綉緇滅鐞嗗憳鍙渶瑕佺洃鎺ч偅浜涚敤鏉ヤ笌鍏跺畠鐨勭綉緇滆澶囦簰榪炵殑绔彛銆傝繖浜涚鍙g殑OID鏈夌殑鏄繛緇殑錛屾湁鐨勫垯鏄垎鏁g殑錛屼絾閮藉睘浜?1.3.6.1.2.1.2.2.1.7鐨勫垎鏀?br />



CPU Statistics

Load
1 minute Load: .1.3.6.1.4.1.2021.10.1.3.1
5 minute Load: .1.3.6.1.4.1.2021.10.1.3.2
15 minute Load: .1.3.6.1.4.1.2021.10.1.3.3

CPU
percentage of user CPU time: .1.3.6.1.4.1.2021.11.9.0
raw user cpu time: .1.3.6.1.4.1.2021.11.50.0
percentages of system CPU time: .1.3.6.1.4.1.2021.11.10.0
raw system cpu time: .1.3.6.1.4.1.2021.11.52.0
percentages of idle CPU time: .1.3.6.1.4.1.2021.11.11.0
raw idle cpu time: .1.3.6.1.4.1.2021.11.53.0
raw nice cpu time: .1.3.6.1.4.1.2021.11.51.0

Memory Statistics

Total Swap Size: .1.3.6.1.4.1.2021.4.3.0
Available Swap Space: .1.3.6.1.4.1.2021.4.4.0
Total RAM in machine: .1.3.6.1.4.1.2021.4.5.0
Total RAM used: .1.3.6.1.4.1.2021.4.6.0
Total RAM Free: .1.3.6.1.4.1.2021.4.11.0
Total RAM Shared: .1.3.6.1.4.1.2021.4.13.0
Total RAM Buffered: .1.3.6.1.4.1.2021.4.14.0
Total Cached Memory: .1.3.6.1.4.1.2021.4.15.0

Disk Statistics

The snmpd.conf needs to be edited. Add the following (assuming a machine with a single / partition):

disk / 100000 (or)

includeAllDisks 10% for all partitions and disks

The OIDs are as follows

Path where the disk is mounted: .1.3.6.1.4.1.2021.9.1.2.1
Path of the device for the partition: .1.3.6.1.4.1.2021.9.1.3.1
Total size of the disk/partion (kBytes): .1.3.6.1.4.1.2021.9.1.6.1
Available space on the disk: .1.3.6.1.4.1.2021.9.1.7.1
Used space on the disk: .1.3.6.1.4.1.2021.9.1.8.1
Percentage of space used on disk: .1.3.6.1.4.1.2021.9.1.9.1
Percentage of inodes used on disk: .1.3.6.1.4.1.2021.9.1.10.1

]]>
OIDhttp://m.tkk7.com/Vincent-chenxj/archive/2009/06/18/283089.htmlVincent-chenVincent-chenThu, 18 Jun 2009 09:20:00 GMThttp://m.tkk7.com/Vincent-chenxj/archive/2009/06/18/283089.htmlhttp://m.tkk7.com/Vincent-chenxj/comments/283089.htmlhttp://m.tkk7.com/Vincent-chenxj/archive/2009/06/18/283089.html#Feedback0http://m.tkk7.com/Vincent-chenxj/comments/commentRss/283089.htmlhttp://m.tkk7.com/Vincent-chenxj/services/trackbacks/283089.html 鏈嶅姟鍣ㄨ繕鍖呮嫭紜洏鍒╃敤鐜囥?br />


1銆佸湪windows涓婂畨瑁卻nmp錛氭帶鍒墮潰鏉?>娣誨姞/鍒犻櫎紼嬪簭->娣誨姞/鍒犻櫎windows緇勪歡->綆$悊鍜岀洃瑙嗗伐鍏?>璇︾粏淇℃伅->snmp鍗忚
2銆佽浣犱滑鍏堣鐪熶簡瑙e涔燩HP銆傚湪鏈哄櫒涓婂畨瑁匒PACHE+PHP+MYSQL鐨勮璁$幆澧冿紝騫剁啛鎮夌幆澧冦傛湁闂闅忔椂鑱旂郴鎴戙?br /> 3銆佷綘鍙互鍦ㄦ湰鏈哄畨瑁卻nmp agent 錛屼箣鍚庤鍙栨湰鏈虹殑鐩稿叧鍙傛暟銆?       

閮ㄥ垎閲嶈OID淇℃伅錛?br /> 1銆佸唴瀛樺ぇ灝?br /> 鏈嶅姟鍣ㄥ唴瀛樼殑OID鏄細.1.3.6.1.2.1.25.2.2.0錛屼笉鍚岀殑鎿嶄綔緋葷粺涔熸槸浣跨敤涓鏍風殑OID銆備絾鏄綉緇滆澶囧唴瀛樼殑OID鏍規嵁璁懼鐨勭敓浜у巶鍟嗕笉鍚屻佸瀷鍙蜂笉鍚岋紝鍏禣ID涔熸槸涓嶅悓鐨勩侰isco鐨勮礬鐢卞櫒鍜屼氦鎹㈡満閮芥槸.1.3.6.1.4.1.9.9.48.1.1.1.5.1銆傚崕涓轟氦鎹㈡満Huawei 6502銆丠uawei 3526銆丠uawei 2403鐨凮ID鏄?1.3.6.1.4.1.2011.6.1.2.1.1.2.0銆傝屽崕涓夌殑H3C E328鍜孒3C E126鐨凮ID鏄?1.3.6.1.4.1.2011.6.1.2.1.1.2.65536銆?br /> 2銆?nbsp;       鍐呭瓨鍒╃敤鐜?br /> 涓庡唴瀛樺ぇ灝忕殑OID鐩稿搴旓紝鍚勮鐩戞帶瀵硅薄鐨勫唴瀛樺埄鐢ㄧ巼鐨凮ID濡備笅錛?br /> 鏈嶅姟鍣ㄥ唴瀛樺埄鐢ㄧ巼鐨凮ID鏄?1.3.6.1.4.1.2021.4.6.0錛涘崕涓轟氦鎹㈡満鐨凮ID鏄?1.3.6.1.4.1.2011.6.1.2.1.1.3.0銆傚崕涓変氦鎹㈡満鐨凮ID鏄?1.3.6.1.4.1.2011.6.1.2.1.1.3.65536銆?br /> 3銆?nbsp;       紜洏澶у皬鍙婂埄鐢ㄧ巼
瀵逛簬鏈嶅姟鍣ㄧ殑紜洏絀洪棿鏉ヨ錛屽洜涓烘瘡涓湇鍔″櫒鐨勭‖鐩樹釜鏁板拰鐩綍鍒掑垎閮戒笉涓鏍鳳紝鎵浠ヨ鍙栧埌鐨勭洰褰曠┖闂村ぇ灝忓搴旂殑OID渚濇涓猴細.1.3.6.1.2.1.25.2.3.1.5.1 銆?1.3.6.1.2.1.25.2.3.1.5.2絳夛紝騫朵笖鍦ㄨ鍙栨瘡涓洰褰曠┖闂村ぇ灝忕殑鍚屾椂瑕佽鍙栬鐩綍鐨勫悕縐幫紙OID渚濇涓猴細.1.3.6.1.2.1.25.2.3.1.3.1銆?1.3.6.1.2.1.25.2.3.1.3.2絳夛級浣滀負璇ョ洃鎺у璞$殑鎻忚堪銆傚叧浜庣洰褰曠┖闂寸殑鍒╃敤鐜囨病鏈夌幇鎴愮殑OID錛岄渶瑕佸厛鑾峰緱鐩綍絀洪棿鐨勪嬌鐢ㄩ噺錛圤ID渚濇涓猴細.1.3.6.1.2.1.25.2.3.1.6.1銆?1.3.6.1.2.1.25.2.3.1.6.2銆佺瓑錛夛紝鐒跺悗閫氳繃浣跨敤閲忎笌絀洪棿鎬婚噺鐨勬瘮杈冨緱鍑哄埄鐢ㄧ巼銆?br /> 4銆?nbsp;       绔彛鐘舵?br /> 瀵逛簬鏈嶅姟鍣ㄦ潵璇達紝鏈夌殑鏈嶅姟鍣ㄤ負浜嗗畬鎴愬鏉傜殑鍔熻兘闇瑕侀厤緗鍧楃綉鍗★紝鍥犳涔熷氨浼氭湁澶氫釜绔彛闇瑕佺洃鎺с傚叧浜庣鍙g姸鎬佺殑OID鍒欎緷嬈′負錛?1.3.6.1.2.1.2.2.1.7.1銆?1.3.6.1.2.1.2.2.1.7.2銆?1.3.6.1.2.1.2.2.1.7.3絳夛紝闄や簡绔彛鐘舵佺郴緇熻繕闇瑕佺煡閬撹绔彛鐨勫悕縐幫紙OID渚濇涓猴細.1.3.6.1.2.1.2.2.1銆?.1銆?1.3.6.1.2.1.2.2.1.2.2銆?1.3.6.1.2.1.2.2.1.2.3絳夛級銆傚湪鑾峰彇浜ゆ崲鏈虹殑绔彛鐘舵佹椂棣栧厛鍙皢鐘舵乁P鐨勭鍙d俊鎭褰曚笅鏉ワ紝鍐嶉氳繃姣忎釜绔彛鐨勪綔鐢ㄦ潵閫夋嫨鏄惁鐪熺殑瀵瑰叾榪涜鐩戞帶銆備竴鑸綉緇滅鐞嗗憳鍙渶瑕佺洃鎺ч偅浜涚敤鏉ヤ笌鍏跺畠鐨勭綉緇滆澶囦簰榪炵殑绔彛銆傝繖浜涚鍙g殑OID鏈夌殑鏄繛緇殑錛屾湁鐨勫垯鏄垎鏁g殑錛屼絾閮藉睘浜?1.3.6.1.2.1.2.2.1.7鐨勫垎鏀?br />



CPU Statistics

Load
1 minute Load: .1.3.6.1.4.1.2021.10.1.3.1
5 minute Load: .1.3.6.1.4.1.2021.10.1.3.2
15 minute Load: .1.3.6.1.4.1.2021.10.1.3.3

CPU
percentage of user CPU time: .1.3.6.1.4.1.2021.11.9.0
raw user cpu time: .1.3.6.1.4.1.2021.11.50.0
percentages of system CPU time: .1.3.6.1.4.1.2021.11.10.0
raw system cpu time: .1.3.6.1.4.1.2021.11.52.0
percentages of idle CPU time: .1.3.6.1.4.1.2021.11.11.0
raw idle cpu time: .1.3.6.1.4.1.2021.11.53.0
raw nice cpu time: .1.3.6.1.4.1.2021.11.51.0

Memory Statistics

Total Swap Size: .1.3.6.1.4.1.2021.4.3.0
Available Swap Space: .1.3.6.1.4.1.2021.4.4.0
Total RAM in machine: .1.3.6.1.4.1.2021.4.5.0
Total RAM used: .1.3.6.1.4.1.2021.4.6.0
Total RAM Free: .1.3.6.1.4.1.2021.4.11.0
Total RAM Shared: .1.3.6.1.4.1.2021.4.13.0
Total RAM Buffered: .1.3.6.1.4.1.2021.4.14.0
Total Cached Memory: .1.3.6.1.4.1.2021.4.15.0

Disk Statistics

The snmpd.conf needs to be edited. Add the following (assuming a machine with a single / partition):

disk / 100000 (or)

includeAllDisks 10% for all partitions and disks

The OIDs are as follows

Path where the disk is mounted: .1.3.6.1.4.1.2021.9.1.2.1
Path of the device for the partition: .1.3.6.1.4.1.2021.9.1.3.1
Total size of the disk/partion (kBytes): .1.3.6.1.4.1.2021.9.1.6.1
Available space on the disk: .1.3.6.1.4.1.2021.9.1.7.1
Used space on the disk: .1.3.6.1.4.1.2021.9.1.8.1
Percentage of space used on disk: .1.3.6.1.4.1.2021.9.1.9.1
Percentage of inodes used on disk: .1.3.6.1.4.1.2021.9.1.10.1

]]>
Cisco甯哥敤OIDhttp://m.tkk7.com/Vincent-chenxj/archive/2009/06/18/283080.htmlVincent-chenVincent-chenThu, 18 Jun 2009 08:48:00 GMThttp://m.tkk7.com/Vincent-chenxj/archive/2009/06/18/283080.htmlhttp://m.tkk7.com/Vincent-chenxj/comments/283080.htmlhttp://m.tkk7.com/Vincent-chenxj/archive/2009/06/18/283080.html#Feedback0http://m.tkk7.com/Vincent-chenxj/comments/commentRss/283080.htmlhttp://m.tkk7.com/Vincent-chenxj/services/trackbacks/283080.html
緋葷粺鐘舵佺浉鍏籌細
### THIS FILE WAS GENERATED BY MIB2SCHEMA
"org"		"1.3"
"dod"		"1.3.6"
"internet"		"1.3.6.1"
"directory"		"1.3.6.1.1"
"mgmt"		"1.3.6.1.2"
"experimental"		"1.3.6.1.3"
"private"		"1.3.6.1.4"
"enterprises"		"1.3.6.1.4.1"
"cisco"		"1.3.6.1.4.1.9"
"ciscoMgmt"		"1.3.6.1.4.1.9.9"
"ciscoEnvMonMIB"		"1.3.6.1.4.1.9.9.13"
"ciscoEnvMonObjects"		"1.3.6.1.4.1.9.9.13.1"
"ciscoEnvMonMIBNotificationEnables"		"1.3.6.1.4.1.9.9.13.2"
"ciscoEnvMonMIBNotificationPrefix"		"1.3.6.1.4.1.9.9.13.3"
"ciscoEnvMonMIBConformance"		"1.3.6.1.4.1.9.9.13.4"
"ciscoEnvMonPresent"		"1.3.6.1.4.1.9.9.13.1.1"
"ciscoEnvMonVoltageStatusTable"		"1.3.6.1.4.1.9.9.13.1.2"
"ciscoEnvMonTemperatureStatusTable"		"1.3.6.1.4.1.9.9.13.1.3"
"ciscoEnvMonFanStatusTable"		"1.3.6.1.4.1.9.9.13.1.4"
"ciscoEnvMonSupplyStatusTable"		"1.3.6.1.4.1.9.9.13.1.5"
"ciscoEnvMonAlarmContacts"		"1.3.6.1.4.1.9.9.13.1.6"
"ciscoEnvMonVoltageStatusEntry"		"1.3.6.1.4.1.9.9.13.1.2.1"
"ciscoEnvMonVoltageStatusIndex"		"1.3.6.1.4.1.9.9.13.1.2.1.1"
"ciscoEnvMonVoltageStatusDescr"		"1.3.6.1.4.1.9.9.13.1.2.1.2"
"ciscoEnvMonVoltageStatusValue"		"1.3.6.1.4.1.9.9.13.1.2.1.3"
"ciscoEnvMonVoltageThresholdLow"		"1.3.6.1.4.1.9.9.13.1.2.1.4"
"ciscoEnvMonVoltageThresholdHigh"		"1.3.6.1.4.1.9.9.13.1.2.1.5"
"ciscoEnvMonVoltageLastShutdown"		"1.3.6.1.4.1.9.9.13.1.2.1.6"
"ciscoEnvMonVoltageState"		"1.3.6.1.4.1.9.9.13.1.2.1.7"
"ciscoEnvMonTemperatureStatusEntry"		"1.3.6.1.4.1.9.9.13.1.3.1"
"ciscoEnvMonTemperatureStatusIndex"		"1.3.6.1.4.1.9.9.13.1.3.1.1"
"ciscoEnvMonTemperatureStatusDescr"		"1.3.6.1.4.1.9.9.13.1.3.1.2"
"ciscoEnvMonTemperatureStatusValue"		"1.3.6.1.4.1.9.9.13.1.3.1.3"
"ciscoEnvMonTemperatureThreshold"		"1.3.6.1.4.1.9.9.13.1.3.1.4"
"ciscoEnvMonTemperatureLastShutdown"		"1.3.6.1.4.1.9.9.13.1.3.1.5"
"ciscoEnvMonTemperatureState"		"1.3.6.1.4.1.9.9.13.1.3.1.6"
"ciscoEnvMonFanStatusEntry"		"1.3.6.1.4.1.9.9.13.1.4.1"
"ciscoEnvMonFanStatusIndex"		"1.3.6.1.4.1.9.9.13.1.4.1.1"
"ciscoEnvMonFanStatusDescr"		"1.3.6.1.4.1.9.9.13.1.4.1.2"
"ciscoEnvMonFanState"		"1.3.6.1.4.1.9.9.13.1.4.1.3"
"ciscoEnvMonSupplyStatusEntry"		"1.3.6.1.4.1.9.9.13.1.5.1"
"ciscoEnvMonSupplyStatusIndex"		"1.3.6.1.4.1.9.9.13.1.5.1.1"
"ciscoEnvMonSupplyStatusDescr"		"1.3.6.1.4.1.9.9.13.1.5.1.2"
"ciscoEnvMonSupplyState"		"1.3.6.1.4.1.9.9.13.1.5.1.3"
"ciscoEnvMonSupplySource"		"1.3.6.1.4.1.9.9.13.1.5.1.4"
"ciscoEnvMonEnableShutdownNotification"		"1.3.6.1.4.1.9.9.13.2.1"
"ciscoEnvMonEnableVoltageNotification"		"1.3.6.1.4.1.9.9.13.2.2"
"ciscoEnvMonEnableTemperatureNotification"		"1.3.6.1.4.1.9.9.13.2.3"
"ciscoEnvMonEnableFanNotification"		"1.3.6.1.4.1.9.9.13.2.4"
"ciscoEnvMonEnableRedundantSupplyNotification"		"1.3.6.1.4.1.9.9.13.2.5"
"ciscoEnvMonEnableStatChangeNotif"		"1.3.6.1.4.1.9.9.13.2.6"
"ciscoEnvMonMIBNotifications"		"1.3.6.1.4.1.9.9.13.3"
"ciscoEnvMonMIBCompliances"		"1.3.6.1.4.1.9.9.13.4.1"
"ciscoEnvMonMIBGroups"		"1.3.6.1.4.1.9.9.13.4.2"
"ciscoEnvMonMIBCompliance"		"1.3.6.1.4.1.9.9.13.4.1.1"
"ciscoEnvMonMIBComplianceRev1"		"1.3.6.1.4.1.9.9.13.4.1.2"
"ciscoEnvMonMIBGroup"		"1.3.6.1.4.1.9.9.13.4.2.1"
"ciscoEnvMonMIBGroupRev"		"1.3.6.1.4.1.9.9.13.4.2.2"
"ciscoEnvMonEnableStatChangeGroup"		"1.3.6.1.4.1.9.9.13.4.2.3"
"ciscoEnvMonMIBNotifGroup"		"1.3.6.1.4.1.9.9.13.4.2.4"
"ciscoEnvMonStatChangeNotifGroup"		"1.3.6.1.4.1.9.9.13.4.2.5"
"ciscoEnvMonMIBMiscNotifGroup"		"1.3.6.1.4.1.9.9.13.4.2.6"
緋葷粺鍐呭瓨淇℃伅錛?/pre>
### THIS FILE WAS GENERATED BY MIB2SCHEMA
"org"		"1.3"
"dod"		"1.3.6"
"internet"		"1.3.6.1"
"directory"		"1.3.6.1.1"
"mgmt"		"1.3.6.1.2"
"experimental"		"1.3.6.1.3"
"private"		"1.3.6.1.4"
"enterprises"		"1.3.6.1.4.1"
"cisco"		"1.3.6.1.4.1.9"
"ciscoMgmt"		"1.3.6.1.4.1.9.9"
"ciscoMemoryPoolMIB"		"1.3.6.1.4.1.9.9.48"
"ciscoMemoryPoolObjects"		"1.3.6.1.4.1.9.9.48.1"
"ciscoMemoryPoolNotifications"		"1.3.6.1.4.1.9.9.48.2"
"ciscoMemoryPoolConformance"		"1.3.6.1.4.1.9.9.48.3"
"ciscoMemoryPoolTable"		"1.3.6.1.4.1.9.9.48.1.1"
"ciscoMemoryPoolUtilizationTable"		"1.3.6.1.4.1.9.9.48.1.2"
"ciscoMemoryPoolEntry"		"1.3.6.1.4.1.9.9.48.1.1.1"
"ciscoMemoryPoolType"		"1.3.6.1.4.1.9.9.48.1.1.1.1"
"ciscoMemoryPoolName"		"1.3.6.1.4.1.9.9.48.1.1.1.2"
"ciscoMemoryPoolAlternate"		"1.3.6.1.4.1.9.9.48.1.1.1.3"
"ciscoMemoryPoolValid"		"1.3.6.1.4.1.9.9.48.1.1.1.4"
"ciscoMemoryPoolUsed"		"1.3.6.1.4.1.9.9.48.1.1.1.5"
"ciscoMemoryPoolFree"		"1.3.6.1.4.1.9.9.48.1.1.1.6"
"ciscoMemoryPoolLargestFree"		"1.3.6.1.4.1.9.9.48.1.1.1.7"
"ciscoMemoryPoolUtilizationEntry"		"1.3.6.1.4.1.9.9.48.1.2.1"
"ciscoMemoryPoolUtilization1Min"		"1.3.6.1.4.1.9.9.48.1.2.1.1"
"ciscoMemoryPoolUtilization5Min"		"1.3.6.1.4.1.9.9.48.1.2.1.2"
"ciscoMemoryPoolUtilization10Min"		"1.3.6.1.4.1.9.9.48.1.2.1.3"
"ciscoMemoryPoolCompliances"		"1.3.6.1.4.1.9.9.48.3.1"
"ciscoMemoryPoolGroups"		"1.3.6.1.4.1.9.9.48.3.2"
"ciscoMemoryPoolCompliance"		"1.3.6.1.4.1.9.9.48.3.1.1"
"ciscoMemoryPoolComplianceRev1"		"1.3.6.1.4.1.9.9.48.3.1.2"
"ciscoMemoryPoolGroup"		"1.3.6.1.4.1.9.9.48.3.2.1"
"ciscoMemoryPoolUtilizationGroup"		"1.3.6.1.4.1.9.9.48.3.2.2"




]]>Communicating with SNMP using C# - The Very Beginning http://m.tkk7.com/Vincent-chenxj/archive/2009/06/18/283059.htmlVincent-chenVincent-chenThu, 18 Jun 2009 07:30:00 GMThttp://m.tkk7.com/Vincent-chenxj/archive/2009/06/18/283059.htmlhttp://m.tkk7.com/Vincent-chenxj/comments/283059.htmlhttp://m.tkk7.com/Vincent-chenxj/archive/2009/06/18/283059.html#Feedback1http://m.tkk7.com/Vincent-chenxj/comments/commentRss/283059.htmlhttp://m.tkk7.com/Vincent-chenxj/services/trackbacks/283059.html

Who Should Read This

  1. You want to program SNMP with C# but have no idea for beginning.
  2. You've googled for a while, but don't get a simple working example.
  3. What you're looking for, is just a simple requirement to get a status value from a device through SNMP.

Introduction
My purpose is to get an uint value from a temperature sensor through SNMP. This is a very simple requirement, and I don't want to understand the whole detail of SNMP protocol. In JAVA, there's lot of open source resources for SNMP programming, for example, SNMP4j. How ever, I found no simple guidance for C# SNMP programming. If you have the same problem, you can have following example to start your way toward SNMP.

Pre-requirement
  1. C# Programming Basics
  2. A working SNMP host to communicate with. For example, a temperature sensor, a networked printer or a router with SNMP functions.
Sample SNMP Class
Firstly, you have to add a reference to OLEPRNLIB. You can find it from "Add reference" -> "COM". The path of the dll is located at C:\Windows\System32 by Default.

Here is a sample SNMP Class:

using System;
using System.Collections.Generic;
using System.Text;
using OLEPRNLib;

namespace MrFu
{
public class SimpleSnmp
{
private String hostIp;
private String oid;
private String communityString;

int retries = 1;
int timeout = 3000;

SNMP snmp = new SNMP();

public SimpleSnmp(String hostIp, String communityString, String oid)
{
this.hostIp = hostIp;
this.communityString = communityString;
this.oid = oid;

try
{
snmp.Open(this.hostIp, this.communityString, this.retries, this.timeout);
}
catch (Exception ex) {
Console.WriteLine(ex.Message);
}

}

public String getValue() {
try
{
uint result = snmp.GetAsByte(this.oid);
return result.ToString();
}
catch (Exception ex) {
Console.WriteLine(ex.Message);
return null;
}
}
}
}


Description for the Code

First line you need to look at is:
snmp.Open(this.hostIp, this.communityString, this.retries, this.timeout);
where the "hostIp" is the IP address of the target, of course,

the "communityString" is "public" by default for most SNMP device. If you changed it on device configuration, remember to modify it.

the "retries" and "timeout" indicate how many times the system should retry if connection failed over the milliseconds given by "timeout".

And, That's All to Connect to A Device Through SNMP. COOL!

Second line you might want to know is:
uint result = snmp.GetAsByte(this.oid);
That's the basic way to get the status or value from your host device. You can convert it into String or any thing you like.

To explain in a simple way, the "oid" is the unique id for some status on the device. You can obtain the correct oid from your device manual. For example, the oid of my temperature sensor is:
".1.3.6.1.4.1.3854.1.2.2.1.16.1.3.0"
So you should be able to find some string looks like that from your device suppliers or documents.

For more detailed description of SNMP protocol, you can look into wikipedia.

That's all. So easy, and you can have a first shot of SNMP programming with C# now.


Conclusin
This is quiet a easy way to have a quick look of SNMP progamming with C#. Surely, the detailed packet parsing or other SNMP functions are NOT shown in this post. But that's all I need to solve my problem. And I hope this post can help you, too.

]]>
SQL鍩烘湰璇彞http://m.tkk7.com/Vincent-chenxj/articles/245153.htmlVincent-chenVincent-chenTue, 09 Dec 2008 02:02:00 GMThttp://m.tkk7.com/Vincent-chenxj/articles/245153.htmlhttp://m.tkk7.com/Vincent-chenxj/comments/245153.htmlhttp://m.tkk7.com/Vincent-chenxj/articles/245153.html#Feedback0http://m.tkk7.com/Vincent-chenxj/comments/commentRss/245153.htmlhttp://m.tkk7.com/Vincent-chenxj/services/trackbacks/245153.html鎺屾彙SQL鍥涙潯鏈鍩烘湰鐨勬暟鎹搷浣滆鍙ワ細Insert錛孲elect錛孶pdate鍜孌elete銆?br />
銆銆 緇冩帉鎻QL鏄暟鎹簱鐢ㄦ埛鐨勫疂璐佃儲 瀵屻傚湪鏈枃涓紝鎴戜滑灝嗗紩瀵間綘鎺屾彙鍥涙潯鏈鍩烘湰鐨勬暟鎹搷浣滆鍙モ擲QL鐨勬牳蹇冨姛鑳解旀潵渚濇浠嬬粛姣旇緝鎿嶄綔絎︺侀夋嫨鏂█浠ュ強涓夊奸昏緫銆傚綋浣犲畬鎴愯繖浜涘涔犲悗錛屾樉鐒朵綘宸茬粡寮濮嬬畻鏄簿閫歋QL浜嗐?br />
銆銆鍦ㄦ垜浠紑濮嬩箣鍓嶏紝鍏堜嬌鐢–REATE TABLE璇彞鏉ュ垱寤轟竴涓〃錛堝鍥?鎵紺猴級銆侱DL璇彞瀵規暟鎹簱瀵硅薄濡傝〃銆佸垪鍜岃榪涜瀹氫箟銆傚畠浠茍涓嶅琛ㄤ腑鐨勮榪涜澶勭悊錛岃繖鏄洜涓篋DL璇彞騫朵笉澶勭悊鏁版嵁搴撲腑瀹為檯鐨勬暟鎹傝繖浜涘伐浣滅敱鍙︿竴綾籗QL璇彞鈥旀暟鎹搷浣滆璦錛圖ML錛夎鍙ヨ繘琛屽鐞嗐?br />
銆銆SQL涓湁鍥涚鍩烘湰鐨凞ML鎿嶄綔錛欼NSERT錛孲ELECT錛孶PDATE鍜孌ELETE銆傜敱浜庤繖鏄ぇ澶氭暟SQL鐢ㄦ埛緇忓父鐢ㄥ埌鐨勶紝鎴戜滑鏈夊繀瑕佸湪姝ゅ瀹冧滑榪涜涓涓璇存槑銆傚湪鍥?涓垜浠粰鍑轟簡涓涓悕涓篍MPLOYEES鐨勮〃銆傚叾涓殑姣忎竴琛屽搴斾竴涓壒瀹氱殑闆囧憳璁板綍銆傝鐔熸倝榪欏紶琛紝鎴戜滑鍦ㄥ悗闈㈢殑渚嬪瓙涓皢瑕佺敤鍒板畠銆?br />
銆銆INSERT璇彞

銆銆鐢ㄦ埛鍙互鐢↖NSERT璇彞灝嗕竴琛岃褰曟彃鍏ュ埌鎸囧畾鐨勪竴涓〃涓備緥濡傦紝瑕佸皢闆囧憳John Smith鐨勮褰曟彃鍏ュ埌鏈緥鐨勮〃涓紝鍙互浣跨敤濡備笅璇彞錛?br />
銆銆INSERT INTO EMPLOYEES VALUES

銆銆 ('Smith','John','1980-06-10',

銆銆 'Los Angles',16,45000);

銆銆閫氳繃榪欐牱鐨処NSERT璇彞錛岀郴緇熷皢璇曠潃灝嗚繖浜涘煎~鍏ュ埌鐩稿簲鐨勫垪涓傝繖浜涘垪鎸夌収鎴戜滑鍒涘緩琛ㄦ椂瀹氫箟鐨勯『搴忔帓鍒椼傚湪鏈緥涓紝絎竴涓?#8220;Smith”灝嗗~鍒扮涓涓垪LAST_NAME涓紱絎簩涓?#8220;John”灝嗗~鍒扮浜屽垪FIRST_NAME涓?#8230;…浠ユ綾繪帹銆?br />
銆銆鎴戜滑璇磋繃緋葷粺浼?#8220;璇曠潃”灝嗗煎~鍏ワ紝闄や簡鎵ц瑙勫垯涔嬪瀹冭繕瑕佽繘琛岀被鍨嬫鏌ャ傚鏋滅被鍨嬩笉絎︼紙濡傚皢涓涓瓧絎︿覆濉叆鍒扮被鍨嬩負鏁板瓧鐨勫垪涓級錛岀郴緇熷皢鎷掔粷榪欎竴嬈℃搷浣滃茍榪斿洖涓涓敊璇俊鎭?br />
銆銆濡傛灉SQL鎷掔粷浜嗕綘鎵濉叆鐨勪竴鍒楀鹼紝璇彞涓叾浠栧悇鍒楃殑鍊間篃涓嶄細濉叆銆傝繖鏄洜涓篠QL鎻愪緵瀵逛簨鍔$殑鏀寔銆備竴嬈′簨鍔″皢鏁版嵁搴撲粠涓縐嶄竴鑷存ц漿縐誨埌鍙︿竴縐嶄竴鑷存с傚鏋滀簨鍔$殑鏌愪竴閮ㄥ垎澶辮觸錛屽垯鏁翠釜浜嬪姟閮戒細澶辮觸錛岀郴緇熷皢浼氳鎭㈠錛堟垨縐頒箣涓哄洖閫錛夊埌姝や簨鍔′箣鍓嶇殑鐘舵併?br />
銆銆 鍥炲埌鍘熸潵鐨処NSERT鐨勪緥瀛愶紝璇鋒敞鎰忔墍鏈夌殑鏁村艦鍗佽繘鍒舵暟閮戒笉闇瑕佺敤鍗曞紩鍙峰紩璧鋒潵錛岃屽瓧絎︿覆鍜屾棩鏈熺被鍨嬬殑鍊奸兘瑕佺敤鍗曞紩鍙鋒潵鍖哄埆銆備負浜嗗鍔犲彲璇繪ц屽湪鏁板瓧闂存彃鍏ラ楀彿灝嗕細寮曡搗閿欒銆傝浣忥紝鍦⊿QL涓楀彿鏄厓绱犵殑鍒嗛殧絎︺?br />
銆銆鍚屾牱瑕佹敞鎰忚緭鍏ユ枃瀛楀兼椂瑕佷嬌鐢ㄥ崟寮曞彿銆傚弻寮曞彿鐢ㄦ潵灝佽闄愮晫鏍囪瘑絎︺?br />
銆銆瀵逛簬鏃ユ湡綾誨瀷錛屾垜浠繀欏諱嬌鐢⊿QL鏍囧噯鏃ユ湡鏍煎紡錛坹yyy-mm-dd錛夛紝浣嗘槸鍦ㄧ郴緇熶腑鍙互榪涜瀹氫箟錛屼互鎺ュ彈鍏朵粬鐨勬牸寮忋傚綋鐒訛紝2000騫翠復榪戯紝璇蜂綘鏈濂借繕鏄嬌鐢ㄥ洓浣嶆潵琛ㄧず騫翠喚銆?br />
銆銆鏃㈢劧浣犲凡緇忕悊瑙d簡INSERT璇彞鏄庢牱宸ヤ綔鐨勪簡錛岃鎴戜滑杞埌EMPLOYEES琛ㄤ腑鐨勫叾浠栭儴鍒嗭細

銆銆INSERT INTO EMPLOYEES VALUES

銆銆 ('Bunyan','Paul','1970-07-04',

銆銆 'Boston',12,70000);

銆銆INSERT INTO EMPLOYEES VALUES

銆銆 ('John','Adams','1992-01-21',

銆銆 'Boston',20,100000);

銆銆INSERT INTO EMPLOYEES VALUES

銆銆 ('Smith','Pocahontas','1976-04-06',

銆銆 'Los Angles',12,100000);

銆銆INSERT INTO EMPLOYEES VALUES

銆銆 ('Smith','Bessie','1940-05-02',

銆銆 'Boston',5,200000);

銆銆INSERT INTO EMPLOYEES VALUES

銆銆 ('Jones','Davy','1970-10-10',

銆銆 'Boston',8,45000);

銆銆INSERT INTO EMPLOYEES VALUES

銆銆 ('Jones','Indiana','1992-02-01',

銆銆 'Chicago',NULL,NULL);

銆銆鍦ㄦ渶鍚庝竴欏逛腑錛屾垜浠笉鐭ラ亾Jones鍏堢敓鐨勫伐钖駭鍒拰騫磋柂錛屾墍浠ユ垜浠緭鍏ULL錛堜笉瑕佸紩鍙鳳級銆侼ULL鏄疭QL涓殑涓縐嶇壒孌婃儏鍐碉紝鎴戜滑浠ュ悗灝嗚繘琛岃緇嗙殑璁ㄨ銆傜幇鍦ㄦ垜浠彧闇璁や負NULL琛ㄧず涓縐嶆湭鐭ョ殑鍊箋?br />
銆銆鏈夋椂錛屽儚鎴戜滑鍒氭墠鎵璁ㄨ鐨勬儏鍐碉紝鎴戜滑鍙兘甯屾湜瀵規煇涓浜涜屼笉鏄叏閮ㄧ殑鍒楄繘琛岃祴鍊箋傞櫎浜嗗瑕佺渷鐣ョ殑鍒楄緭鍏ULL澶栵紝榪樺彲浠ラ噰鐢ㄥ彟澶栦竴縐岻NSERT璇彞錛屽涓嬶細

銆銆INSERT INTO EMPLOYEES(

銆銆 FIRST_NAME, LAST_NAME,

銆銆 HIRE_DATE, BRANCH_OFFICE)

銆銆VALUE(

銆銆 'Indiana','Jones',

銆銆 '1992-02-01','Indianapolis');

銆銆榪欐牱錛屾垜浠厛鍦ㄨ〃鍚嶄箣鍚庡垪鍑轟竴緋誨垪鍒楀悕銆傛湭鍒楀嚭鐨勫垪涓皢鑷姩濉叆緙虹渷鍊鹼紝濡傛灉娌℃湁璁劇疆緙虹渷鍊煎垯濉叆NULL銆傝娉ㄦ剰鎴戜滑鏀瑰彉浜嗗垪鐨勯『搴忥紝鑰屽肩殑欏哄簭瑕佸搴旀柊鐨勫垪鐨勯『搴忋傚鏋滆璇彞涓渷鐣ヤ簡FIRST_NAME鍜孡AST_NAME欏癸紙榪欎袱欏硅瀹氫笉鑳戒負絀猴級錛孲QL鎿嶄綔灝嗗け璐ャ?br />
銆銆璁╂垜浠潵鐪嬩竴鐪嬩笂榪癐NSERT璇彞鐨勮娉曞浘錛?br />
銆銆INSERT INTO table

銆銆 [(column { ,column})]

銆銆VALUES

銆銆 (columnvalue [{,columnvalue}]);

銆銆鍜屽墠涓綃囨枃绔犱腑涓鏍鳳紝鎴戜滑鐢ㄦ柟鎷彿鏉ヨ〃紺哄彲閫夐」錛屽ぇ鎷彿琛ㄧず鍙互閲嶅浠繪剰嬈℃暟鐨勯」錛堜笉鑳藉湪瀹為檯鐨凷QL璇彞涓嬌鐢ㄨ繖浜涚壒孌婂瓧絎︼級銆俈ALUE瀛愬彞鍜屽彲閫夌殑鍒楀悕鍒楄〃涓繀欏諱嬌鐢ㄥ渾鎷彿銆?br />
銆銆SELECT璇彞

銆銆SELECT璇彞鍙互浠庝竴涓垨澶氫釜琛ㄤ腑閫夊彇鐗瑰畾鐨勮鍜屽垪銆傚洜涓烘煡璇㈠拰媯绱㈡暟鎹槸鏁版嵁搴撶鐞嗕腑鏈閲嶈鐨勫姛鑳斤紝鎵浠ELECT璇彞鍦⊿QL涓槸宸ヤ綔閲忔渶澶х殑閮ㄥ垎銆傚疄闄呬笂錛屼粎浠呮槸璁塊棶鏁版嵁搴撴潵鍒嗘瀽鏁版嵁騫剁敓鎴愭姤琛ㄧ殑浜哄彲浠ュ鍏朵粬SQL璇彞涓紿嶄笉閫氥?br />
銆銆SELECT璇彞鐨勭粨鏋滈氬父鏄敓鎴愬彟澶栦竴涓〃銆傚湪鎵ц榪囩▼涓郴緇熸牴鎹敤鎴風殑鏍囧噯浠庢暟鎹簱涓夊嚭鍖歸厤鐨勮鍜屽垪錛屽茍灝嗙粨鏋滄斁鍒頒復鏃剁殑琛ㄤ腑銆傚湪鐩存帴SQL錛坉irect SQL錛変腑錛屽畠灝嗙粨鏋滄樉紺哄湪緇堢鐨勬樉紺哄睆涓婏紝鎴栬呭皢緇撴灉閫佸埌鎵撳嵃鏈烘垨鏂囦歡涓備篃鍙互緇撳悎鍏朵粬SQL璇彞鏉ュ皢緇撴灉鏀懼埌涓涓凡鐭ュ悕縐扮殑琛ㄤ腑銆?br />
銆銆SELECT璇彞鍔熻兘寮哄ぇ銆傝櫧鐒惰〃闈笂鐪嬫潵瀹冨彧鐢ㄦ潵瀹屾垚鏈枃絎竴閮ㄥ垎涓彁鍒扮殑鍏崇郴浠f暟榪愮畻“閫夋嫨”錛堟垨縐?#8220;闄愬埗”錛夛紝浣嗗疄闄呬笂瀹冧篃鍙互瀹屾垚鍏朵粬涓ょ鍏崇郴榪愮畻鈥?#8220;鎶曞獎”鍜?#8220;榪炴帴”錛孲ELECT璇彞榪樺彲浠ュ畬鎴愯仛鍚堣綆楀茍瀵規暟鎹繘琛屾帓搴忋?br />
銆銆SELECT璇彞鏈綆鍗曠殑璇硶濡備笅錛?br />
銆銆SELECT columns FROM tables;

銆銆褰撴垜浠互榪欑褰㈠紡鎵ц涓鏉ELECT璇彞鏃訛紝緋葷粺榪斿洖鐢辨墍閫夋嫨鐨勫垪浠ュ強鐢ㄦ埛閫夋嫨鐨勮〃涓墍鏈夋寚瀹氱殑琛岀粍鎴愮殑涓涓粨鏋滆〃銆傝繖灝辨槸瀹炵幇鍏崇郴鎶曞獎榪愮畻鐨勪竴涓艦寮忋?br />
銆銆璁╂垜浠湅涓涓嬩嬌鐢ㄥ浘1涓璄MPLOYEES琛ㄧ殑涓浜涗緥瀛愶紙榪欎釜琛ㄦ槸鎴戜滑浠ュ悗鎵鏈塖ELECT璇彞瀹炰緥閮借浣跨敤鐨勩傝屾垜浠湪鍥?鍜屽浘3涓粰鍑轟簡鏌ヨ鐨勫疄闄呯粨鏋溿傛垜浠皢鍦ㄥ叾浠栫殑渚嬪瓙涓嬌鐢ㄨ繖浜涚粨鏋滐級銆?br />
銆銆鍋囪浣犳兂鏌ョ湅闆囧憳宸ヤ綔閮ㄩ棬鐨勫垪琛ㄣ傞偅涓嬮潰灝辨槸浣犳墍闇瑕佺紪鍐欑殑SQL鏌ヨ錛?br />
銆銆SELECT BRANCH_OFFICE FROM EMPLOYEES;

銆銆浠ヤ笂SELECT璇彞鐨勬墽琛屽皢浜х敓濡傚浘2涓〃2鎵紺虹殑緇撴灉銆?br />
銆銆鐢變簬鎴戜滑鍦⊿ELECT璇彞涓彧鎸囧畾浜嗕竴涓垪錛屾墍浠ユ垜浠殑緇撴灉琛ㄤ腑涔熷彧鏈変竴涓垪銆傛敞鎰忕粨鏋滆〃涓叿鏈夐噸澶嶇殑琛岋紝榪欐槸鍥犱負鏈夊涓泧鍛樺湪鍚屼竴閮ㄩ棬宸ヤ綔錛堣浣廠QL浠庢墍閫夌殑鎵鏈夎涓皢鍊艱繑鍥烇級銆傝娑堥櫎緇撴灉涓殑閲嶅琛岋紝鍙鍦⊿ELECT璇彞涓姞涓奃ISTINCT瀛愬彞錛?br />
銆銆SELECT DISTINCT BRANCH_OFFICE

銆銆FROM EMPLOYEES;

銆銆榪欐鏌ヨ鐨勭粨鏋滃琛?鎵紺恒?br />
銆銆鐜板湪宸茬粡娑堥櫎浜嗛噸澶嶇殑琛岋紝浣嗙粨鏋滃茍涓嶆槸鎸夌収欏哄簭鎺掑垪鐨勩傚鏋滀綘甯屾湜浠ュ瓧姣嶈〃欏哄簭灝嗙粨鏋滃垪鍑哄張璇ユ庝箞鍋氬憿錛熷彧瑕佷嬌鐢∣RDER BY瀛愬彞灝卞彲浠ユ寜鐓у崌搴忔垨闄嶅簭鏉ユ帓鍒楃粨鏋滐細

銆銆SELECT DISTINCT BRANCH_OFFICE

銆銆FROM EMPLOYEES

銆銆ORDER BY BRANCH_OFFICE ASC;

銆銆榪欎竴鏌ヨ鐨勭粨鏋滃琛?鎵紺恒傝娉ㄦ剰鍦∣RDER BY涔嬪悗鏄浣曟斁緗垪鍚岯RANCH _OFFICE鐨勶紝榪欏氨鏄垜浠兂瑕佸鍏惰繘琛屾帓搴忕殑鍒椼備負浠涔堝嵆浣挎槸緇撴灉琛ㄤ腑鍙湁涓涓垪鏃舵垜浠篃蹇呴』鎸囧嚭鍒楀悕鍛紵榪欐槸鍥犱負鎴戜滑榪樿兘澶熸寜鐓ц〃涓叾浠栧垪榪涜鎺掑簭錛屽嵆浣垮畠浠茍涓嶆樉紺哄嚭鏉ャ傚垪鍚岯RANCH_ OFFICE涔嬪悗鐨勫叧閿瓧ASC琛ㄧず鎸夌収鍗囧簭鎺掑垪銆傚鏋滀綘甯屾湜浠ラ檷搴忔帓鍒楋紝閭d箞鍙互鐢ㄥ叧閿瓧DESC銆?br />
銆銆鍚屾牱鎴戜滑搴旇鎸囧嚭ORDER BY瀛愬彞鍙皢涓存椂琛ㄤ腑鐨勭粨鏋滆繘琛屾帓搴忥紱騫朵笉褰卞搷鍘熸潵鐨勮〃銆?br />
銆銆鍋囪鎴戜滑甯屾湜寰楀埌鎸夐儴闂ㄦ帓搴忓茍浠庡伐璧勬渶楂樼殑闆囧憳鍒板伐璧勬渶浣庣殑闆囧憳鎺掑垪鐨勫垪琛ㄣ傞櫎浜嗗伐璧勬嫭鍙蜂腑鐨勫唴瀹癸紝鎴戜滑榪樺笇鏈涚湅鍒版寜鐓ц仒鐢ㄦ椂闂翠粠鏈榪戣仒鐢ㄧ殑闆囧憳寮濮嬪垪鍑虹殑鍒楄〃銆備互涓嬫槸浣犲皢瑕佺敤鍒扮殑璇彞錛?br />
銆銆SELECT BRANCH_OFFICE,FIRST_NAME,

銆銆 LAST_NAME,SALARY,HIRE_DATE

銆銆FROM EMPLOYEES

銆銆ORDER BY SALARY DESC,

銆銆 HIRE_DATE DESC;

銆銆榪欓噷鎴戜滑榪涜浜嗗鍒楃殑閫夋嫨鍜屾帓搴忋傛帓搴忕殑浼樺厛綰х敱璇彞涓殑鍒楀悕欏哄簭鎵鍐沖畾銆係QL灝嗗厛瀵瑰垪鍑虹殑絎竴涓垪榪涜鎺掑簭銆傚鏋滃湪絎竴涓垪涓嚭鐜頒簡閲嶅鐨勮鏃訛紝榪欎簺琛屽皢琚寜鐓х浜屽垪榪涜鎺掑簭錛屽鏋滃湪絎簩鍒椾腑鍙堝嚭鐜頒簡閲嶅鐨勮鏃訛紝榪欎簺琛屽張灝嗚鎸夌収絎笁鍒楄繘琛屾帓搴?#8230;…濡傛綾繪帹銆傝繖嬈℃煡璇㈢殑緇撴灉濡傝〃5鎵紺恒?br />
銆銆灝嗕竴涓緢闀跨殑琛ㄤ腑鐨勬墍鏈夊垪鍚嶅啓鍑烘潵鏄竴浠剁浉褰撻夯鐑︾殑浜嬶紝鎵浠QL鍏佽鍦ㄩ夋嫨琛ㄤ腑鎵鏈夌殑鍒楁椂浣跨敤*鍙鳳細

銆銆SELECT * FROM EMPLOYEES;

銆銆榪欐鏌ヨ榪斿洖鏁翠釜EMPLOYEES琛紝濡傝〃1鎵紺恒?br />
銆銆 涓嬮潰鎴戜滑瀵瑰紑濮嬫椂緇欏嚭鐨凷ELECT璇彞鐨勮娉曡繘琛屼竴涓嬫洿鏂幫紙绔栫洿綰胯〃紺轟竴涓彲閫夐」錛屽厑璁稿湪鍏朵腑閫夋嫨涓欏廣傦級錛?br />
銆銆SELECT [DISTINCT]

銆銆 (column [{, columns}])| *

銆銆FROM table [ {, table}]

銆銆[ORDER BY column [ASC] | DESC

銆銆 [ {, column [ASC] | DESC }]];

銆銆瀹氫箟閫夋嫨鏍囧噯

銆銆鍦ㄦ垜浠洰鍓嶆墍浠嬬粛鐨凷ELECT璇彞涓紝鎴戜滑瀵圭粨鏋滆〃涓殑鍒椾綔鍑轟簡閫夋嫨浣嗚繑鍥炵殑鏄〃涓墍鏈夌殑琛屻傝鎴戜滑鐪嬩竴涓嬪浣曞SELECT璇彞榪涜闄愬埗浣垮緱瀹冨彧榪斿洖甯屾湜寰楀埌鐨勮錛?br />
銆銆SELECT columns FROM tables [WHERE predicates];

銆銆WHERE瀛愬彞瀵規潯浠惰繘琛屼簡璁劇疆錛屽彧鏈夋弧瓚蟲潯浠剁殑琛屾墠琚寘鎷埌緇撴灉琛ㄤ腑銆傝繖浜涙潯浠剁敱鏂█錛坧redicate錛夎繘琛屾寚瀹氾紙鏂█鎸囧嚭浜嗗叧浜庢煇浠朵簨鎯呯殑涓縐嶅彲鑳界殑浜嬪疄錛夈傚鏋滆鏂█瀵逛簬鏌愪釜緇欏畾鐨勮鎴愮珛錛岃琛屽皢琚寘鎷埌緇撴灉琛ㄤ腑錛屽惁鍒欒琛岃蹇界暐銆傚湪SQL璇彞涓柇璦閫氬父閫氳繃姣旇緝鏉ヨ〃紺恒備緥濡傦紝鍋囧浣犻渶瑕佹煡璇㈡墍鏈夊涓篔ones鐨勮亴鍛橈紝鍒欏彲浠ヤ嬌鐢ㄤ互涓婼ELECT璇彞錛?br />
銆銆SELECT * FROM EMPLOYEES

銆銆WHERE LAST_NAME = 'Jones';

銆銆LAST_NAME = 'Jones'閮ㄥ垎灝辨槸鏂█銆傚湪鎵ц璇ヨ鍙ユ椂錛孲QL灝嗘瘡涓琛岀殑LAST_NAME鍒椾笌“Jones”榪涜姣旇緝銆傚鏋滄煇涓鑱屽憳鐨勫涓?#8220;Jones”錛屽嵆鏂█鎴愮珛錛岃鑱屽憳鐨勪俊鎭皢琚寘鎷埌緇撴灉琛ㄤ腑錛堣琛?錛夈?br />
銆銆浣跨敤鏈澶氱殑鍏姣旇緝

銆銆鎴戜滑涓婁緥涓殑鏂█鍖呮嫭涓縐嶅熀浜?#8220;絳夊?#8221;鐨勬瘮杈冿紙LAST_NAME = 'Jones'錛夛紝浣嗘槸SQL鏂█榪樺彲浠ュ寘鍚叾浠栧嚑縐嶇被鍨嬬殑姣旇緝銆傚叾涓渶甯哥敤鐨勪負錛?br />
銆銆絳変簬 =

銆銆涓嶇瓑浜?<>

銆銆灝忎簬 <

銆銆澶т簬 >

銆銆灝忎簬鎴栫瓑浜?<=

銆銆澶т簬鎴栫瓑浜?>=

銆銆涓嬮潰緇欏嚭浜嗕笉鏄熀浜庣瓑鍊兼瘮杈冪殑涓涓緥瀛愶細

銆銆SELECT * FROM EMPLOYEES

銆銆WHERE SALARY > 50000;

銆銆榪欎竴鏌ヨ灝嗚繑鍥炲勾钖珮浜?50,000.00鐨勮亴鍛橈紙鍙傝琛?錛夈?br />
銆銆閫昏緫榪炴帴絎?br />
銆銆鏈夋椂鎴戜滑闇瑕佸畾涔変竴鏉′笉姝竴縐嶆柇璦鐨凷ELECT璇彞銆備婦渚嬫潵璇達紝濡傛灉浣犱粎浠呮兂鏌ョ湅Davy Jones鐨勪俊鎭殑璇濓紝琛?涓殑緇撴灉灝嗘槸涓嶆紜殑銆備負浜嗚繘涓姝ュ畾涔変竴涓猈HERE瀛愬彞錛岀敤鎴峰彲浠ヤ嬌鐢ㄩ昏緫榪炴帴絎ND錛孫R鍜孨OT銆備負浜嗗彧寰楀埌鑱屽憳Davy Jones鐨勮褰曪紝鐢ㄦ埛鍙互杈撳叆濡備笅璇彞錛?br />
銆銆SELECT * FROM EMPLOYEES

銆銆WHERE LAST_NAME = 'Jones' AND FIRST_NAME = 'Davy';

銆銆鍦ㄦ湰渚嬩腑錛屾垜浠氳繃閫昏緫榪炴帴絎ND灝嗕袱涓柇璦榪炴帴璧鋒潵銆傚彧鏈変袱涓柇璦閮芥弧瓚蟲椂鏁翠釜琛ㄨ揪寮忔墠浼氭弧瓚熾傚鏋滅敤鎴烽渶瑕佸畾涔変竴涓猄ELECT璇彞鏉ヤ嬌寰楀綋鍏朵腑浠諱綍涓欏規垚绔嬪氨婊¤凍鏉′歡鏃訛紝鍙互浣跨敤OR榪炴帴絎︼細

銆銆SELECT * FROM EMPLOYEES

銆銆WHERE LAST_NAME = 'Jones' OR LAST_NAME = 'Smith';

銆銆鏈夋椂瀹氫箟涓涓柇璦鐨勬渶濂芥柟娉曟槸閫氳繃鐩稿弽鐨勬弿榪版潵璇存槑銆傚鏋滀綘鎯寵鏌ョ湅闄や簡Boston鍔炰簨澶勭殑鑱屽憳浠ュ鐨勫叾浠栨墍鏈夎亴鍛樼殑淇℃伅鏃訛紝浣犲彲浠ヨ繘琛屽涓嬬殑鏌ヨ錛?br />
銆銆SELECT * FROM EMPLOYEES

銆銆WHERE NOT(BRANCH_OFFICE = 'Boston');

銆銆鍏抽敭瀛桸OT鍚庨潰璺熺潃鐢ㄥ渾鎷彿鎷搗鏉ョ殑姣旇緝琛ㄨ揪寮忋傚叾緇撴灉鏄緇撴灉鍙栧惁瀹氥傚鏋滄煇涓鑱屽憳鎵鍦ㄩ儴闂ㄧ殑鍔炰簨澶勫湪Boston錛屾嫭鍙峰唴鐨勮〃杈懼紡榪斿洖true錛屼絾鏄疦OT鎿嶄綔絎﹀皢璇ュ煎彇鍙嶏紝鎵浠ヨ琛屽皢涓嶈閫変腑銆?br />
銆銆鏂█鍙互涓庡叾浠栫殑鏂█宓屽浣跨敤銆備負浜嗕繚璇佸畠浠互姝g‘鐨勯『搴忚繘琛屾眰鍊鹼紝鍙互鐢ㄦ嫭鍙峰皢瀹冧滑鎷搗鏉ワ細

銆銆SELECT * FROM EMPLOYEES

銆銆WHERE (LAST_NAME = 'Jones'

銆銆AND FIRST_NAME = 'Indiana')

銆銆OR (LAST_NAME = 'Smith'

銆銆AND FIRST_NAME = 'Bessie');

銆銆SQL娌跨敤鏁板涓婃爣鍑嗙殑琛ㄨ揪寮忔眰鍊肩殑綰﹀畾鈥斿渾鎷彿鍐呯殑琛ㄨ揪寮忓皢鏈鍏堣繘琛屾眰鍊鹼紝鍏朵粬琛ㄨ揪寮忓皢浠庡乏鍒板彸榪涜姹傚箋?br />
銆銆浠ヤ笂瀵歸昏緫榪炴帴絎﹁繘琛屼簡璇存槑錛屽湪瀵逛笅闈㈢殑鍐呭榪涜璇存槑涔嬪墠錛屾垜浠啀涓嬈″SELECT璇彞鐨勮娉曡繘琛屾洿鏂幫細

銆銆SELECT [DISTINCT]

銆銆 (column [{, column } ] )| *

銆銆FROM table [ { , table} ]

銆銆[ORDER BY column [ASC] | [DESC

銆銆[{ , column [ASC] | [DESC } ] ]

銆銆WHERE predicate [ { logical-connector predicate } ];

銆銆NULL鍜屼笁鍊奸昏緫

銆銆鍦⊿QL涓璑ULL鏄竴涓鏉傜殑璇濋錛屽叧浜嶯ULL鐨勮緇嗘弿榪版洿閫傚悎浜庡湪SQL鐨勯珮綰ф暀紼嬭屼笉鏄幇鍦ㄧ殑鍏ラ棬鏁欑▼涓繘琛屼粙緇嶃備絾鐢變簬NULL闇瑕佽繘琛岀壒孌婂鐞嗭紝騫朵笖浣犱篃寰堝彲鑳戒細閬囧埌瀹冿紝鎵浠ユ垜浠繕鏄畝鐣ュ湴榪涜涓涓嬭鏄庛?br />
銆銆棣栧厛錛屽湪鏂█涓繘琛孨ULL鍒ゆ柇鏃墮渶瑕佺壒孌婄殑璇硶銆備緥濡傦紝濡傛灉鐢ㄦ埛闇瑕佹樉紺烘墍鏈夊勾钖湭鐭ョ殑鑱屽憳鐨勫叏閮ㄤ俊鎭紝鐢ㄦ埛鍙互浣跨敤濡備笅SELECT璇彞錛?br />
銆銆SELECT * FROM EMPLOYEES

銆銆WHERE SALARY IS NULL;

銆銆鐩稿弽錛屽鏋滅敤鎴烽渶瑕佹墍鏈夊凡鐭ュ勾钖暟鎹殑鑱屽憳鐨勪俊鎭紝浣犲彲浠ヤ嬌鐢ㄤ互涓嬭鍙ワ細

銆銆SELECT * FROM EMPLOYEES

銆銆WHERE SALARY IS NOT NULL;

銆銆璇鋒敞鎰忔垜浠湪鍒楀悕涔嬪悗浣跨敤浜嗗叧閿瓧IS NULL鎴朓S NOT NULL錛岃屼笉鏄爣鍑嗙殑姣旇緝褰㈠紡錛欳OLUMN = NULL銆丆OLUMN <> NULL鎴栨槸閫昏緫鎿嶄綔絎OT錛圢ULL錛夈?br />
銆銆榪欑褰㈠紡鐩稿綋綆鍗曘備絾褰撲綘涓嶆槑紜湴嫻嬭瘯NULL錛堣屽畠浠‘瀹炲瓨鍦級鏃訛紝浜嬫儏浼氬彉寰楀緢娣蜂貢銆?br />
銆銆渚嬪錛屽洖榪囧ご鏉ョ湅鎴戜滑鍥?涓殑EM-PLOYEES琛紝鍙互鐪嬪埌Indiana Jones鐨勫伐钖瓑綰ф垨騫磋柂鍊奸兘鏄湭鐭ョ殑銆傝繖涓や釜鍒楅兘鍖呭惈NULL銆傚彲浠ユ兂璞¤繍琛屽涓嬬殑鏌ヨ錛?br />
銆銆SELECT * FROM EMPLOYEES

銆銆WHERE GRADE <= SALARY;

銆銆姝ゆ椂錛孖ndiana Jones搴旇鍑虹幇鍦ㄧ粨鏋滆〃涓傚洜涓篘ULL閮芥槸鐩哥瓑鐨勶紝鎵浠ュ彲浠ユ兂璞″畠浠槸鑳藉閫氳繃GRADE灝忎簬絳変簬SALARY鐨勬鏌ョ殑銆傝繖鍏跺疄鏄竴涓鏃犵枒涔夌殑鏌ヨ錛屼絾鏄茍娌℃湁鍏崇郴銆係QL鍏佽榪涜榪欐牱鐨勬瘮杈冿紝鍙涓や釜鍒楅兘鏄暟瀛楃被鍨嬬殑銆傜劧鑰岋紝Indiana Jones騫舵病鏈夊嚭鐜板湪鏌ヨ鐨勭粨鏋滀腑錛屼負浠涔堬紵

銆銆姝e鎴戜滑鏃╁厛鎻愬埌榪囩殑錛孨ULL琛ㄧず鏈煡鐨勫鹼紙鑰屼笉鏄薄鏌愪簺浜烘墍鎯寵薄鐨勯偅鏍瘋〃紺轟竴涓負NULL鐨勫鹼級銆傚浜嶴QL鏉ヨ鎰忓懗鐫榪欎釜鍊兼槸鏈煡鐨勶紝鑰屽彧瑕佽繖涓間負鏈煡錛屽氨涓嶈兘灝嗗叾涓庡叾浠栧兼瘮杈冿紙鍗充嬌鍏朵粬鍊間篃鏄疦ULL錛夈傛墍浠QL鍏佽闄や簡鍦╰rue 鍜宖alse涔嬪榪樻湁絎笁縐嶇被鍨嬬殑鐪熷鹼紝縐頒箣涓?#8220;闈炵‘瀹?#8221;錛坲nknown錛夊箋?br />
銆銆濡傛灉姣旇緝鐨勪袱杈歸兘鏄疦ULL錛屾暣涓柇璦灝辮璁や負鏄潪紜畾鐨勩傚皢涓涓潪紜畾鏂█鍙栧弽鎴栦嬌鐢ˋND鎴朞R涓庡叾浠栨柇璦榪涜鍚堝茍涔嬪悗錛屽叾緇撴灉浠嶆槸闈炵‘瀹氱殑銆傜敱浜庣粨鏋滆〃涓彧鍖呮嫭鏂█鍊間負“鐪?#8221;鐨勮錛屾墍浠ULL涓嶅彲鑳芥弧瓚寵媯鏌ャ備粠鑰岄渶瑕佷嬌鐢ㄧ壒孌婄殑鎿嶄綔絎S NULL鍜孖S NOT NULL銆?br />
銆銆UPDATE璇彞

銆銆UPDATE璇彞鍏佽鐢ㄦ埛鍦ㄥ凡鐭ョ殑琛ㄤ腑瀵圭幇鏈夌殑琛岃繘琛屼慨鏀廣?br />
銆銆渚嬪錛屾垜浠垰鍒氬彂鐜癐ndiana Jones鐨勭瓑綰т負16錛屽伐璧勪負$40,000.00錛屾垜浠彲浠ラ氳繃涓嬮潰鐨凷QL璇彞瀵規暟鎹簱榪涜鏇存柊錛堝茍娓呴櫎閭d簺鐑︿漢鐨凬ULL錛夈?br />
銆銆UPDATE EMPLOYEES

銆銆SET GRADE = 16, SALARY = 40000

銆銆WHERE FIRST_NAME = 'Indiana'

銆銆 AND LAST_NAME = 'Jones';

銆銆涓婇潰鐨勪緥瀛愯鏄庝簡涓涓崟琛屾洿鏂幫紝浣嗘槸UPDATE璇彞鍙互瀵瑰琛岃繘琛屾搷浣溿傛弧瓚砏HERE鏉′歡鐨勬墍鏈夎閮藉皢琚洿鏂般傚鏋滐紝浣犳兂璁〣oston鍔炰簨澶勪腑鐨勬墍鏈夎亴鍛樻惉鍒癗ew York錛屼綘鍙互浣跨敤濡備笅璇彞錛?br />
銆銆UPDATE EMPLOYEES

銆銆SET BRANCH_OFFICE = 'New York'

銆銆WHERE BRANCH_OFFICE = 'Boston';

銆銆濡傛灉蹇界暐WHERE瀛愬彞,琛ㄤ腑鎵鏈夎涓殑閮ㄩ棬鍊奸兘灝嗚鏇存柊涓?New York'銆?br />
銆銆UPDATE璇彞鐨勮娉曟祦鍥懼涓嬮潰鎵紺猴細

銆銆UPDATE table

銆銆SET column = value [{, column = value}]

銆銆[ WHERE predicate [ { logical-connector predicate}]];

銆銆DELETE璇彞

銆銆DELETE璇彞鐢ㄦ潵鍒犻櫎宸茬煡琛ㄤ腑鐨勮銆傚鍚孶PDATE璇彞涓竴鏍鳳紝鎵鏈夋弧瓚砏HERE瀛愬彞涓潯浠剁殑琛岄兘灝嗚鍒犻櫎銆傜敱浜嶴QL涓病鏈塙NDO璇彞鎴栨槸“浣犵‘璁ゅ垹闄ゅ悧錛?#8221;涔嬬被鐨勮鍛婏紝鍦ㄦ墽琛岃繖鏉¤鍙ユ椂鍗冧竾瑕佸皬蹇冦傚鏋滃喅瀹氬彇娑圠os Angeles鍔炰簨澶勫茍瑙i泧鍔炰簨澶勭殑鎵鏈夎亴鍛橈紝榪欎竴鍗戦剻鐨勫伐浣滃彲浠ョ敱浠ヤ笅榪欐潯璇彞鏉ュ疄鐜幫細

銆銆DELETE FROM EMPLOYEES

銆銆WHERE BRANCH_OFFICE = 'Los Angeles';

銆銆濡傚悓UPDATE璇彞涓竴鏍鳳紝鐪佺暐WHERE瀛愬彞灝嗕嬌寰楁搷浣滄柦鍔犲埌琛ㄤ腑鎵鏈夌殑琛屻?br />
銆銆DELETE璇彞鐨勮娉曟祦鍥懼涓嬮潰鎵紺猴細

銆銆DELETE FROM table

銆銆[WHERE predicate [ { logical-connector predicate} ] ];

銆銆鐜板湪鎴戜滑瀹屾垚浜嗘暟鎹搷浣滆璦錛圖ML錛夌殑涓昏璇彞鐨勪粙緇嶃傛垜浠茍娌℃湁瀵筍QL鑳藉畬鎴愮殑鎵鏈夊姛鑳借繘琛岃鏄庛係QL榪樻彁渚涗簡璁稿鐨勫姛鑳斤紝濡傛眰騫沖潎鍊箋佹眰鍜屼互鍙婂叾浠栧琛ㄤ腑鏁版嵁鐨勮綆楋紝姝ゅSQL榪樿兘瀹屾垚浠庡涓〃涓繘琛屾煡璇紙澶氳〃鏌ヨ錛屾垨縐頒箣涓鴻繛鎺ワ級鐨勫伐浣溿傝繖縐嶈璦榪樺厑璁鎬綘浣跨敤GRANT鍜孯EVOKE鍛戒護鎺у埗浣跨敤鑰呯殑鏁版嵁璁塊棶鏉冮檺銆?/span>

]]>
JSF闂闆嗛敠http://m.tkk7.com/Vincent-chenxj/articles/243633.htmlVincent-chenVincent-chenMon, 01 Dec 2008 01:55:00 GMThttp://m.tkk7.com/Vincent-chenxj/articles/243633.htmlhttp://m.tkk7.com/Vincent-chenxj/comments/243633.htmlhttp://m.tkk7.com/Vincent-chenxj/articles/243633.html#Feedback0http://m.tkk7.com/Vincent-chenxj/comments/commentRss/243633.htmlhttp://m.tkk7.com/Vincent-chenxj/services/trackbacks/243633.html1.濡備綍緇撴潫session?   
  • 浣犲彲浠ヤ嬌鐢╯ession鐨?nbsp;invalidate鏂規硶 .   
  • 涓嬮潰鏄竴涓粠action鏂規硶涓粨鏉焥ession鐨勪緥瀛? :   
  • public String logout() {    
      FacesContext fc 
    = FacesContext.getCurrentInstance();    
      HttpSession session 
    = (HttpSession) fc.getExternalContext().getSession(false);    
      session.invalidate();    
      
    return "login_page";    
    }
       

     

  • 涓嬮潰鐨勪唬鐮佺墖孌電ず渚嬩簡濡備綍鍦↗SP欏甸潰涓粨鏉焥ession:   
  • <% session.invalidate(); %>    
    <c:redirect url="loginPage.jsf" />    
       

  •   
  • 2.濡備綍鍦↗SP欏甸潰涓闂畐eb.xml涓殑鍒濆鍖栧弬鏁?   
  • 浣犲彲浠ヤ嬌鐢ㄩ瀹氫箟鐨凧SF EL鍙橀噺  initParam鏉ヨ闂?   
  • 渚嬪,濡傛灉浣犳湁:   
  •  

    <context-param>    
     
    <param-name>productId</param-name>    
     
    <param-value>2004Q4</param-value>    
    </context-param>    

     

  • 浣犲彲浠ヤ嬌鐢ㄥス #{initParam['productId']}鏉ヨ闂?nbsp;.渚嬪:   
  • Product Id: <h:outputText value="#{initParam['productId']}"/>   
  •   
  •   
  • 3.濡備綍浠巎ava浠g爜涓闂畐eb.xml 涓殑鍒濆鍖栧弬鏁?   
  • 浣犲彲浠ヤ嬌鐢╡xternalContext鐨?nbsp;getInitParameter 鏂規硶寰楀埌浠栦滑.渚嬪 濡傛灉浣犵殑鍙傛暟濡備笅:   
  •  

    <context-param>    
     
    <param-name>connectionString</param-name>    
     
    <param-value>jdbc:oracle:thin:scott/tiger@cartman:1521:O901DB</param-value>    
    </context-param>    

     

  • 浣犲彲浠ヤ嬌鐢ㄤ笅闈唬鐮佽闂甤onnectionString :   
  • FacesContext fc = FacesContext.getCurrentInstance();String connection = fc.getExternalContext().getInitParameter("connectionString");    
  •   
  •   
  • 4.濡備綍浠巄acking bean涓緱鍒板綋鍓嶉〉闈㈢殑URL?   
  • 浣犲彲浠ラ氳繃FacesContext寰楀埌涓涓狧ttp Request瀵硅薄鐨勫紩鐢?濡備笅:   
  • FacesContext fc = FacesContext.getCurrentInstance();HttpServletRequest request = (HttpServletRequest) fc.getExternalContext().getRequest();    
  • 鐒跺悗浣跨敤鏅氱殑request鏂規硶鏉ュ緱鍒拌礬寰勪俊鎭?榪樺彲浠ヤ嬌鐢ㄥ彟澶栦竴縐嶆柟娉?   
  • context.getViewRoot().getViewId();   
  • 灝嗚繑鍥炰綘褰撳墠JSP(JSF view IDs 鍩烘湰涓婂彧鏄疛SP path names)欏甸潰鐨勫悕瀛?   
  •   
  •   
  • 5.濡備綍娣誨姞涓婁笅鏂囪礬寰勫埌outputLink鐨刄RL涓?   
  • 鍦ㄥ綋鍓嶇殑JSF瀹炵幇涓?褰撳湪outputLink 涓畾涔夌殑璺緞浠?/'寮濮嬫椂,娌℃湁娣誨姞涓婁笅鏂囪礬寰勫埌URL涓?瑕佸譏琛ヨ闂璇峰湪URL涓嬌鐢?nbsp;#{facesContext.externalContext.requestContextPath} 鍓嶇紑.渚嬪:   
  • <h:outputLink value="#{facesContext.externalContext.requestContextPath}/myPage.faces">   
  •   
  •   
  • 6.濡備綍浣跨敤URL瀛楃涓叉潵浼犻掑弬鏁板埌JSF紼嬪簭涓?   
  • 濡傛灉浣犳湁涓嬮潰鐨刄RL: http://your_server/your_app/product.jsf?id=777, 浣犲彲浠ヤ嬌鐢ㄤ笅闈㈢殑浠g爜鏉ヨ闂墍浼犻掔殑鍙傛暟:     
  • FacesContext fc = FacesContext.getCurrentInstance();String id = (String) fc.getExternalContext().getRequestParameterMap().get("id");    
  • 鍦↗SF欏甸潰涓?浣犱篃鍙互浣跨敤棰勫畾涔夌殑鍙橀噺璁塊棶鍚屾牱鐨勫弬鏁?渚嬪:    
  • <h:outputText value="#{param['id']}" />   
  • 娉ㄦ剰: 浣犲繀欏葷洿鎺ヨ皟鐢ㄨJSF欏甸潰,騫朵笖浣跨敤servlet 鏄犲皠 (mapping).   
  •   
  •   
  • 7.濡備綍鍦ㄩ〉闈㈤噸鏂拌澆鍏ョ殑鏃跺欎繚鐣檋:inputSecret涓殑瀵嗙爜?   
  • 璁劇疆redisplay=true, it is false by default.   
  •     
  •   
  • 8.濡備綍浣跨敤h:outputText杈撳嚭HTML鏍囩?   
  •   
  • h:outputText鏈変竴涓?nbsp; escape 灞炴х敤鏉ュ鐞唄tml 鏍囩. 榛樿鍊間負true.榪欐剰鍛崇潃鎵鏈夌壒孌婄殑絎﹀悎閮借杞箟涓?&'浠g爜. 璇風湅涓嬮潰紺轟緥:  <h:outputText value="<b>This is a text</b>"/> 鎵撳嵃鐨勭粨鏋滄槸:  <b>This is a text</b>  鑰?nbsp;<h:outputText escape="false" value="<b>This is a text</b>"/>  鎵撳嵃鐨勭粨鏋滄槸:  This is a text  褰撶敤鎴風偣鍑籆ommand Link鍚庡浣曟樉紺虹‘璁ゅ璇濇?   
  • h:commandLink鎸囧畾浜?nbsp;onclick 灞炴т負鍐呴儴浣跨敤. 鍥犳浣犱笉鍙互浣跨敤濂逛簡, 璇ラ棶棰樺凡緇忓湪JSF1.2涓慨澶嶄簡,瀵逛簬JSF1.2浠ュ墠鐨勭増鏈?浣犲彲浠ュ湪onclick浠ュ墠浣跨敤  onmousedown 浜嬩歡  <script  language="javascript">  function ConfirmDelete(link) {    var delete = confirm('Do you want to Delete?');    if (delete == true) {      link.onclick();    }  }</script>   
  • <h:commandLink action="delete" onmousedown="return ConfirmDelete(this);">  <h:outputText value="delete it"/></h:commandLink>   
  •     
  •   
  • 9.鍦ㄨ皟鐢╒alueChangeListener 鏂規硶鍚庡浣曢噸鏂拌杞介〉闈?   
  • 鍦?nbsp;ValueChangeListener鐨勬渶鍚?璋冪敤  FacesContext.getCurrentInstance().renderResponse()   
  • 濡備綍瀹炵幇"璇風瓑寰?.."欏甸潰? 鍦ㄥ鎴風瀹炵幇鍙兘寰堢畝鍗?浣犲彲浠ュ寘瑁匤SP欏甸潰(鎴栬呬綘鎯寵闅愯棌鐨勪竴閮ㄥ垎)鍒頒竴涓猟iv涓?鐒跺悗浣犲彲浠ユ坊鍔犳洿澶歞iv,褰撶敤鎴風偣鍑繪彁浜ゆ寜閽椂榪欎簺div鍑虹幇.榪欎簺div鍙互鍖呭惈gif鍔ㄧ敾鍜屽叾浠栧唴瀹? 鍦烘櫙:褰撶敤鎴風偣鍑繪寜閽?璋冪敤JS鍑芥暟,璇ュ嚱鏁伴殣钘忛〉闈㈠茍涓旀樉紺?/span>"璇風瓑寰?.."div.浣犲彲浠ヤ嬌鐢–SS鏉ヨ嚜瀹氫箟澶栬:涓嬮潰鏄竴涓甯稿伐浣滅殑渚嬪瓙: <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>   
  • <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>    
    <f:loadBundle basename="demo.bundle.Messages" var="Message"/>    
    <html>    
    <head>    
      
    <title>Input Name Page</title>    
      
    <script>    
        function gowait() {    
          document.getElementById("main").style.visibility="hidden";    
          document.getElementById("wait").style.visibility="visible";    
        }    
       
    </script>    
           
     
    </head>    
     
    <body bgcolor="white">    
      
    <f:view>    
        
    <div id="main">    
           
    <h1><h:outputText value="#{Message.inputname_header}"/></h1>    
           
    <h:messages style="color: red"/>    
           
    <h:form id="helloForm">    
             
    <h:outputText value="#{Message.prompt}"/>    
             
    <h:inputText id="userName" value="#{GetNameBean.userName}" required="true">    
               
    <f:validateLength minimum="2" maximum="20"/>    
             
    </h:inputText>    
             
    <h:commandButton onclick="gowait()" id="submit"   
                   action
    ="#{GetNameBean.action}" value="Say Hello" />    
           
    </h:form>    
        
    </div>    
        
    <div id="wait" style="visibility:hidden; position: absolute; top: 0; left: 0">    
           
    <table width="100%" height ="300px">    
             
    <tr>    
               
    <td align="center" valign="middle">    
                 
    <h2>Please, wait</h2>    
               
    </td>    
             
    </tr>    
           
    </table>    
        
    </div>    
      
    </f:view>    
     
    </body>    
    </html>     
       

    濡傛灉浣犳兂鏈変竴涓姩鐢籫if鍥劇墖鍦?/span>"璇風瓑寰?.."涓?褰撹〃鍗曟彁浜ゅ悗璇ュ浘鐗囧簲璇ヤ粠鏂板姞杞?鍥犳,鍐嶄竴嬈℃寚瀹氬浘鐗囩殑id,騫朵笖娣誨姞緇忚繃涓孌墊椂闂村歡鏃跺悗閲嶆柊鍔犺澆鐨勪唬鐮?涓嬮潰鏄釜渚嬪瓙: <script>   

     

     function gowait() {    
       document.getElementById("main").style.visibility="hidden";    
       document.getElementById("wait").style.visibility="visible";    
       window.setTimeout('showProgress()', 500);    
     }    
      function showProgress(){    
       var wg = document.getElementById("waitgif");    
       wg.src=wg.src;    
     }    
    </script>    
    .    
    <img id="waitgif" src="animated.gif">   


    ]]>
    jsf緇撴潫sessionhttp://m.tkk7.com/Vincent-chenxj/articles/243401.htmlVincent-chenVincent-chenSat, 29 Nov 2008 05:06:00 GMThttp://m.tkk7.com/Vincent-chenxj/articles/243401.htmlhttp://m.tkk7.com/Vincent-chenxj/comments/243401.htmlhttp://m.tkk7.com/Vincent-chenxj/articles/243401.html#Feedback0http://m.tkk7.com/Vincent-chenxj/comments/commentRss/243401.htmlhttp://m.tkk7.com/Vincent-chenxj/services/trackbacks/243401.html 涓嬮潰鏄竴涓粠action鏂規硶涓粨鏉焥ession鐨勪緥瀛? :

     

    public String logout() {

      FacesContext fc 
    = FacesContext.getCurrentInstance();
      HttpSession session 
    = (HttpSession) fc.getExternalContext().getSession(false);
      session.invalidate();
      
    return "login_page";
    }
      

     

    涓嬮潰鐨勪唬鐮佺墖孌電ず渚嬩簡濡備綍鍦↗SP欏甸潰涓粨鏉焥ession:

    
    
    <% session.invalidate(); %>
    <c:redirect url="loginPage.jsf" /> 


    ]]>
    鎿嶄綔word鐨勮В鍐蟲柟妗?/title><link>http://m.tkk7.com/Vincent-chenxj/articles/243382.html</link><dc:creator>Vincent-chen</dc:creator><author>Vincent-chen</author><pubDate>Sat, 29 Nov 2008 02:04:00 GMT</pubDate><guid>http://m.tkk7.com/Vincent-chenxj/articles/243382.html</guid><wfw:comment>http://m.tkk7.com/Vincent-chenxj/comments/243382.html</wfw:comment><comments>http://m.tkk7.com/Vincent-chenxj/articles/243382.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/Vincent-chenxj/comments/commentRss/243382.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/Vincent-chenxj/services/trackbacks/243382.html</trackback:ping><description><![CDATA[     鎽樿: /** *//**            *   緄︽枡緄辮▓Excel銉曘偂銈ゃ儷鏇搞亸            *  &nb...  <a href='http://m.tkk7.com/Vincent-chenxj/articles/243382.html'>闃呰鍏ㄦ枃</a><img src ="http://m.tkk7.com/Vincent-chenxj/aggbug/243382.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/Vincent-chenxj/" target="_blank">Vincent-chen</a> 2008-11-29 10:04 <a href="http://m.tkk7.com/Vincent-chenxj/articles/243382.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>POI 灝嗘暟鎹鍑哄埌Word鐨勫疄渚?/title><link>http://m.tkk7.com/Vincent-chenxj/articles/243381.html</link><dc:creator>Vincent-chen</dc:creator><author>Vincent-chen</author><pubDate>Sat, 29 Nov 2008 01:55:00 GMT</pubDate><guid>http://m.tkk7.com/Vincent-chenxj/articles/243381.html</guid><wfw:comment>http://m.tkk7.com/Vincent-chenxj/comments/243381.html</wfw:comment><comments>http://m.tkk7.com/Vincent-chenxj/articles/243381.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://m.tkk7.com/Vincent-chenxj/comments/commentRss/243381.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/Vincent-chenxj/services/trackbacks/243381.html</trackback:ping><description><![CDATA[<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img src="http://m.tkk7.com/images/OutliningIndicators/None.gif" align="top" alt="" /><span style="color: #0000ff">import</span><span style="color: #000000"> java.io.</span><span style="color: #000000">*</span><span style="color: #000000">; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000"> java.util.</span><span style="color: #000000">*</span><span style="color: #000000">; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000"> org.apache.poi.poifs.filesystem.</span><span style="color: #000000">*</span><span style="color: #000000">; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000"> org.apache.poi.util.LittleEndian; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/None.gif" align="top" alt="" /><br /> <img id="Codehighlighter1_148_851_Open_Image" onclick="this.style.display='none'; Codehighlighter1_148_851_Open_Text.style.display='none'; Codehighlighter1_148_851_Closed_Image.style.display='inline'; Codehighlighter1_148_851_Closed_Text.style.display='inline';" src="http://m.tkk7.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_148_851_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_148_851_Closed_Text.style.display='none'; Codehighlighter1_148_851_Open_Image.style.display='inline'; Codehighlighter1_148_851_Open_Text.style.display='inline';" src="http://m.tkk7.com/images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> WordTest </span><span id="Codehighlighter1_148_851_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://m.tkk7.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_148_851_Open_Text"><span style="color: #000000">{ <br /> <img id="Codehighlighter1_169_172_Open_Image" onclick="this.style.display='none'; Codehighlighter1_169_172_Open_Text.style.display='none'; Codehighlighter1_169_172_Closed_Image.style.display='inline'; Codehighlighter1_169_172_Closed_Text.style.display='inline';" src="http://m.tkk7.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_169_172_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_169_172_Closed_Text.style.display='none'; Codehighlighter1_169_172_Open_Image.style.display='inline'; Codehighlighter1_169_172_Open_Text.style.display='inline';" src="http://m.tkk7.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> WordTest() </span><span id="Codehighlighter1_169_172_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://m.tkk7.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_169_172_Open_Text"><span style="color: #000000">{ <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />}</span></span><span style="color: #000000"> <br /> <img id="Codehighlighter1_240_752_Open_Image" onclick="this.style.display='none'; Codehighlighter1_240_752_Open_Text.style.display='none'; Codehighlighter1_240_752_Closed_Image.style.display='inline'; Codehighlighter1_240_752_Closed_Text.style.display='inline';" src="http://m.tkk7.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_240_752_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_240_752_Closed_Text.style.display='none'; Codehighlighter1_240_752_Open_Image.style.display='inline'; Codehighlighter1_240_752_Open_Text.style.display='inline';" src="http://m.tkk7.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span style="color: #0000ff">boolean</span><span style="color: #000000"> writeWordFile(String path, String content) </span><span id="Codehighlighter1_240_752_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://m.tkk7.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_240_752_Open_Text"><span style="color: #000000">{ <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #0000ff">boolean</span><span style="color: #000000"> w </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">false</span><span style="color: #000000">; <br /> <img id="Codehighlighter1_267_689_Open_Image" onclick="this.style.display='none'; Codehighlighter1_267_689_Open_Text.style.display='none'; Codehighlighter1_267_689_Closed_Image.style.display='inline'; Codehighlighter1_267_689_Closed_Text.style.display='inline';" src="http://m.tkk7.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_267_689_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_267_689_Closed_Text.style.display='none'; Codehighlighter1_267_689_Open_Image.style.display='inline'; Codehighlighter1_267_689_Open_Text.style.display='inline';" src="http://m.tkk7.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" /></span><span style="color: #0000ff">try</span><span style="color: #000000"> </span><span id="Codehighlighter1_267_689_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://m.tkk7.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_267_689_Open_Text"><span style="color: #000000">{ <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #008000">//</span><span style="color: #008000"> byte b[] = content.getBytes("ISO-8859-1"); </span><span style="color: #008000"><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #0000ff">byte</span><span style="color: #000000"> b[] </span><span style="color: #000000">=</span><span style="color: #000000"> content.getBytes(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />ByteArrayInputStream bais </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> ByteArrayInputStream(b); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />POIFSFileSystem fs </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> POIFSFileSystem(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />DirectoryEntry directory </span><span style="color: #000000">=</span><span style="color: #000000"> fs.getRoot(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />DocumentEntry de </span><span style="color: #000000">=</span><span style="color: #000000"> directory.createDocument(</span><span style="color: #000000">"</span><span style="color: #000000">WordDocument</span><span style="color: #000000">"</span><span style="color: #000000">, bais); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />FileOutputStream ostream </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> FileOutputStream(path); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />fs.writeFilesystem(ostream); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />bais.close(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />ostream.close(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img id="Codehighlighter1_713_738_Open_Image" onclick="this.style.display='none'; Codehighlighter1_713_738_Open_Text.style.display='none'; Codehighlighter1_713_738_Closed_Image.style.display='inline'; Codehighlighter1_713_738_Closed_Text.style.display='inline';" src="http://m.tkk7.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_713_738_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_713_738_Closed_Text.style.display='none'; Codehighlighter1_713_738_Open_Image.style.display='inline'; Codehighlighter1_713_738_Open_Text.style.display='inline';" src="http://m.tkk7.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />}</span></span><span style="color: #000000"> </span><span style="color: #0000ff">catch</span><span style="color: #000000"> (IOException e) </span><span id="Codehighlighter1_713_738_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://m.tkk7.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_713_738_Open_Text"><span style="color: #000000">{ <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />e.printStackTrace(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />}</span></span><span style="color: #000000"> <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #0000ff">return</span><span style="color: #000000"> w; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />}</span></span><span style="color: #000000"> <br /> <img id="Codehighlighter1_793_848_Open_Image" onclick="this.style.display='none'; Codehighlighter1_793_848_Open_Text.style.display='none'; Codehighlighter1_793_848_Closed_Image.style.display='inline'; Codehighlighter1_793_848_Closed_Text.style.display='inline';" src="http://m.tkk7.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_793_848_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_793_848_Closed_Text.style.display='none'; Codehighlighter1_793_848_Open_Image.style.display='inline'; Codehighlighter1_793_848_Open_Text.style.display='inline';" src="http://m.tkk7.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> main(String[] args)</span><span id="Codehighlighter1_793_848_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://m.tkk7.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_793_848_Open_Text"><span style="color: #000000">{ <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #0000ff">boolean</span><span style="color: #000000"> b </span><span style="color: #000000">=</span><span style="color: #000000"> writeWordFile(</span><span style="color: #000000">"</span><span style="color: #000000">E://test.doc</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">"</span><span style="color: #000000">hello</span><span style="color: #000000">"</span><span style="color: #000000">); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />}</span></span><span style="color: #000000"> <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" />}</span></span><span style="color: #000000"> <br /> <img id="Codehighlighter1_854_5064_Open_Image" onclick="this.style.display='none'; Codehighlighter1_854_5064_Open_Text.style.display='none'; Codehighlighter1_854_5064_Closed_Image.style.display='inline'; Codehighlighter1_854_5064_Closed_Text.style.display='inline';" src="http://m.tkk7.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_854_5064_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_854_5064_Closed_Text.style.display='none'; Codehighlighter1_854_5064_Open_Image.style.display='inline'; Codehighlighter1_854_5064_Open_Text.style.display='inline';" src="http://m.tkk7.com/images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /></span><span id="Codehighlighter1_854_5064_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff">/**/</span><span id="Codehighlighter1_854_5064_Open_Text"><span style="color: #008000">/*</span><span style="color: #008000"> <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />public String extractText(InputStream in) throws IOException { <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />ArrayList text = new ArrayList(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />POIFSFileSystem fsys = new POIFSFileSystem(in); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />DocumentEntry headerProps = (DocumentEntry) fsys.getRoot().getEntry("WordDocument"); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />DocumentInputStream din = fsys.createDocumentInputStream("WordDocument"); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />byte[] header = new byte[headerProps.getSize()]; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />din.read(header); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />din.close(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />// Prende le informazioni dall'header del documento <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />int info = LittleEndian.getShort(header, 0xa); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />boolean useTable1 = (info & 0x200) != 0; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />//boolean useTable1 = true; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />// Prende informazioni dalla piece table <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />int complexOffset = LittleEndian.getInt(header, 0x1a2); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />//int complexOffset = LittleEndian.getInt(header); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />String tableName = null; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />if (useTable1) { <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />tableName = "1Table"; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} else { <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />tableName = "0Table"; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />DocumentEntry table = (DocumentEntry) fsys.getRoot().getEntry(tableName); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />byte[] tableStream = new byte[table.getSize()]; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />din = fsys.createDocumentInputStream(tableName); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />din.read(tableStream); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />din.close(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />din = null; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />fsys = null; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />table = null; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />headerProps = null; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />int multiple = findText(tableStream, complexOffset, text); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />StringBuffer sb = new StringBuffer(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />int size = text.size(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />tableStream = null; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />for (int x = 0; x < size; x++) { <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />WordTextPiece nextPiece = (WordTextPiece) text.get(x); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />int start = nextPiece.getStart(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />int length = nextPiece.getLength(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />boolean unicode = nextPiece.usesUnicode(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />String toStr = null; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />if (unicode) { <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />toStr = new String(header, start, length * multiple, "UTF-16LE"); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} else { <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />toStr = new String(header, start, length, "ISO-8859-1"); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />sb.append(toStr).append(" "); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />return sb.toString(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />private static int findText(byte[] tableStream, int complexOffset, ArrayList text) <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />throws IOException { <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />//actual text <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />int pos = complexOffset; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />int multiple = 2; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />//skips through the prms before we reach the piece table. These contain data <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />//for actual fast saved files <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />while (tableStream[pos] == 1) { <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />pos++; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />int skip = LittleEndian.getShort(tableStream, pos); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />pos += 2 + skip; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />if (tableStream[pos] != 2) { <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />throw new IOException("corrupted Word file"); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} else { <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />//parse out the text pieces <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />int pieceTableSize = LittleEndian.getInt(tableStream, ++pos); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />pos += 4; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />int pieces = (pieceTableSize - 4) / 12; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />for (int x = 0; x < pieces; x++) { <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />int filePos = <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />LittleEndian.getInt(tableStream, pos + ((pieces + 1) * 4) + (x *<img src="http://m.tkk7.com/images/forum/smiles/icon_cool.gif"/> + 2); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />boolean unicode = false; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />if ((filePos & 0x40000000) == 0) { <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />unicode = true; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} else { <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />unicode = false; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />multiple = 1; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />filePos &= ~(0x40000000); //gives me FC in doc stream <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />filePos /= 2; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />int totLength = <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />LittleEndian.getInt(tableStream, pos + (x + 1) * 4) <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />- LittleEndian.getInt(tableStream, pos + (x * 4)); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />WordTextPiece piece = new WordTextPiece(filePos, totLength, unicode); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />text.add(piece); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />return multiple; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />public static void main(String[] args){ <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />WordTest w = new WordTest(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />POIFSFileSystem ps = new POIFSFileSystem(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />try{ <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />File file = new File("C:\\test.doc"); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />InputStream in = new FileInputStream(file); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />String s = w.extractText(in); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />System.out.println(s); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />}catch(Exception e){ <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />e.printStackTrace(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />public boolean writeWordFile(String path, String content) { <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />boolean w = false; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />try { <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />// byte b[] = content.getBytes("ISO-8859-1"); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />byte b[] = content.getBytes(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />ByteArrayInputStream bais = new ByteArrayInputStream(b); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />POIFSFileSystem fs = new POIFSFileSystem(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />DirectoryEntry directory = fs.getRoot(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />DocumentEntry de = directory.createDocument("WordDocument", bais); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />FileOutputStream ostream = new FileOutputStream(path); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />fs.writeFilesystem(ostream); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />bais.close(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />ostream.close(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} catch (IOException e) { <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />e.printStackTrace(); <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />return w; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />class WordTextPiece { <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />private int _fcStart; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />private boolean _usesUnicode; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />private int _length; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />public WordTextPiece(int start, int length, boolean unicode) { <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />_usesUnicode = unicode; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />_length = length; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />_fcStart = start; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />public boolean usesUnicode() { <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />return _usesUnicode; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />public int getStart() { <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />return _fcStart; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />public int getLength() { <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />return _length; <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://m.tkk7.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />} <br /> <img src="http://m.tkk7.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" /></span><span style="color: #008000">*/</span></span><span style="color: #000000"> </span></div> <img src ="http://m.tkk7.com/Vincent-chenxj/aggbug/243381.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/Vincent-chenxj/" target="_blank">Vincent-chen</a> 2008-11-29 09:55 <a href="http://m.tkk7.com/Vincent-chenxj/articles/243381.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <p>感谢您访问我们的网站,您可能还对以下资源感兴趣:</p> <a href="http://m.tkk7.com/" title="亚洲av成人片在线观看">亚洲av成人片在线观看</a> <div class="friend-links"> </div> </div> </footer> 主站蜘蛛池模板: <a href="http://wwwvv99.com" target="_blank">久久综合久久综合亚洲</a>| <a href="http://www-5453.com" target="_blank">无码国产精品一区二区免费</a>| <a href="http://502274.com" target="_blank">亚洲综合激情五月色一区</a>| <a href="http://www-456446.com" target="_blank">亚洲乱码中文字幕综合</a>| <a href="http://2030188.com" target="_blank">日韩在线a视频免费播放</a>| <a href="http://sxjttxkywl.com" target="_blank">无码精品人妻一区二区三区免费看</a>| <a href="http://tj-zhongfa.com" target="_blank">国产亚洲男人的天堂在线观看</a>| <a href="http://woaianli.com" target="_blank">亚洲国产成人资源在线软件</a>| <a href="http://bwgdbjb.com" target="_blank">亚洲精品成人网站在线观看</a>| <a href="http://jiggybaby.com" target="_blank">亚洲av午夜精品一区二区三区</a>| <a href="http://xww678.com" target="_blank">午夜免费福利在线</a>| <a href="http://meixiudashi.com" target="_blank">青青青国产在线观看免费网站</a>| <a href="http://ksdhao.com" target="_blank">久久久精品免费视频</a>| <a href="http://bearsou.com" target="_blank">久久久精品视频免费观看</a>| <a href="http://vvihh.com" target="_blank">水蜜桃视频在线观看免费</a>| <a href="http://ttooyuyu.com" target="_blank">亚洲成a人无码亚洲成av无码</a>| <a href="http://222941.com" target="_blank">亚洲一级免费毛片</a>| <a href="http://51jingpai.com" target="_blank">亚洲永久中文字幕在线</a>| <a href="http://927ff.com" target="_blank">亚洲综合一区二区国产精品</a>| <a href="http://8xxon8.com" target="_blank">亚洲AV无码国产丝袜在线观看</a>| <a href="http://saob19.com" target="_blank">中文字幕精品亚洲无线码一区</a>| <a href="http://ziguang1688.com" target="_blank">免费人成在线观看播放国产</a>| <a href="http://26672814.com" target="_blank">国产高清免费的视频</a>| <a href="http://w9366.com" target="_blank">日本媚薬痉挛在线观看免费</a>| <a href="http://diswooo.com" target="_blank">99精品全国免费观看视频</a>| <a href="http://zz4466.com" target="_blank">中文字幕乱码免费视频</a>| <a href="http://zzzttt669.com" target="_blank">a拍拍男女免费看全片</a>| <a href="http://by9277.com" target="_blank">一级特黄aa毛片免费观看</a>| <a href="http://www52a.com" target="_blank">国产成人无码区免费网站</a>| <a href="http://50077995.com" target="_blank">99免费精品视频</a>| <a href="http://600c20.com" target="_blank">a级成人毛片免费图片</a>| <a href="http://cnpc1002.com" target="_blank">A片在线免费观看</a>| <a href="http://gdbobo.com" target="_blank">午夜影院免费观看</a>| <a href="http://www-333346.com" target="_blank">久9这里精品免费视频</a>| <a href="http://wlzp88.com" target="_blank">亚洲成人免费在线</a>| <a href="http://8mav1000.com" target="_blank">中文字幕亚洲免费无线观看日本</a>| <a href="http://avdian126.com" target="_blank">99爱在线精品视频免费观看9</a>| <a href="http://jyzs888.com" target="_blank">麻豆精品不卡国产免费看</a>| <a href="http://df8848.com" target="_blank">四虎国产成人永久精品免费</a>| <a href="http://18yinren.com" target="_blank">3344永久在线观看视频免费首页</a>| <a href="http://7a37.com" target="_blank">成人女人A级毛片免费软件</a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>