<?xml version="1.0" encoding="gb2312"?>

<!-- RSS generated by oioj.net on 4/16/2004 ; 感谢LeXRus提供 RSS 2.0 文档; 此文件可自由使用，但请保留此行信息 --> 
<!-- Source download URL: http://blogger.org.cn/blog/rss2.asp       -->
<rss version="2.0">

<channel>
<title>小白兔的家</title>
<link>http://blogger.org.cn/blog/blog.asp?name=fishyqd</link>
<description>小鱼儿的博客</description>
<copyright>blogger.org.cn</copyright>
<generator>W3CHINA Blog</generator>
<webMaster>webmaster@blogger.org.cn</webMaster>
<item>
<title><![CDATA[Eclipse 插件汇总（转载+不断更新）]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=fishyqd&amp;id=13152</link>
<author>fishyqd</author>
<pubDate>2006/4/4 10:13:49</pubDate>
<description><![CDATA[让Eclipse可以像JBuilderX一样使用拖拉方式建构GUI的外挂： <BR>1.Jigloo SWT/Swing GUI Builder ： <BR><A href="http://cloudgarden.com/jigloo/index.html" target=_blank>http://cloudgarden.com/jigloo/index.html</A> ;<BR>下载此版本：Jigloo plugin for Eclipse (using Java 1.4 or 1.5) 安装后即可由档案-&gt;新建-&gt;其它-&gt;GUI Form选取要建构的GUI类型。 <BR><BR>2.Eclipse Visual Editor Project： <BR><A href="http://www.eclipse.org/vep/" target=_blank>http://www.eclipse.org/vep/</A> ;<BR>点选下方Download Page，再点选Latest Release 0.5.0进入下载。 <BR>除了VE-runtime-0.5.0.zip要下载外，以下这2个也要： <BR>EMF build 1.1.1: (build page) (download zip) <BR>GEF Build 2.1.2: (build page) (download zip) <BR><BR>3.0 M8版本，请下载： <BR>EMF build I200403250631 <BR>GEF Build I20040330 <BR>VE-runtime-1.0M1 <BR><BR>安装成功后，便可由File-&gt;New-&gt;Visual Class开始UI设计。 <BR>安装成功后，即可由新建-&gt;Java-&gt;AWT与Swing里选择 <BR>所要建构的GUI类型开始进行设计。VE必须配合着对应 <BR>版本，才能正常使用，否则即使安装成功，使用上仍会 <BR>有问题。 <BR><BR>使用Eclipse来开发JSP程序： 外挂名称：lomboz(下载页面) <BR><A href="http://forge.objectweb.org/project/showfiles.php?group_id=97" target=_blank>http://forge.objectweb.org/project/showfiles.php?group_id=97</A> ;<BR>请选择适合自己版本的lomboz下载，lomboz.212.p1.zip表示2.1.2版， <BR>lomboz.3m7.zip表示M7版本....以此类推。 <BR>lomboz安装以及设置教学： <BR>Eclipse开发JSP-教学文件 <BR><BR>Java转exe篇： <BR>实现方式：Eclipse搭配JSmooth(免费)。 <BR>1.先由Eclipse制作包含Manifest的JAR。制作教学 <BR>2.使用JSmooth将做好的JAR包装成EXE。 <BR>JSmooth下载页面： <BR><A href="http://jsmooth.sourceforge.net/index.php" target=_blank>http://jsmooth.sourceforge.net/index.php</A> ;<BR>3.制作完成的exe文件，可在有装置JRE的Windows上执行。 <BR><BR><BR>几个常用的eclipse插件 <BR><BR><BR>1、struts-console、faces-console<BR>开发struts应用之必需控件，对各种struts配置文件进行图形界面操作<BR><A href="http://www.jamesholmes.com/struts/console/" target=_blank>http://www.jamesholmes.com/struts/console/</A><BR><A href="http://www.jamesholmes.com/JavaServerFaces/console/" target=_blank>http://www.jamesholmes.com/JavaServerFaces/console/</A><BR><BR>EasyStruts<BR>　http://easystruts.sourceforge.net<BR><BR>StrutsIDE<BR>( LGPL / J2EE development platform )<BR>updated:2005-5-2<BR>version 1.1.4<BR>StrutsIDE is an Eclipse plugin for web application development using Jakarta Struts Framework. It provides graphical editing for struts-config.xml.<BR><A href="http://amateras.sourceforge.jp/cgi-bin/fswiki_en/wiki.cgi?page=StrutsIDE" target=_blank>http://amateras.sourceforge.jp/cgi-bin/fswiki_en/wiki.cgi?page=StrutsIDE</A><BR><BR><BR>2、xmlBuddy<BR>编辑xml文件的插件，支持代码援助(根据DTD定义)<BR><A href="http://www.xmlbuddy.com/" target=_blank>http://www.xmlbuddy.com</A><BR><BR>3、sysdeo tomcat plug-in<BR>支持开发环境中Tomcat调试<BR><A href="http://www.sysdeo.com/eclipse/tomcatPlugin.html" target=_blank>http://www.sysdeo.com/eclipse/tomcatPlugin.html</A><BR><BR>4、lomboz j2ee plug-in<BR>支持代码援助式编辑jsp文件。eclipse本身也很快就会支持jsp编辑<BR><A href="http://www.objectlearn.com/" target=_blank>http://www.objectlearn.com</A> (学习)<BR><A href="http://forge.objectweb.org/project/showfiles.php?group_id=97" target=_blank>http://forge.objectweb.org/project/showfiles.php?group_id=97</A> (下载)<BR><BR>5、jFacedbc 数据库插件<BR><A href="http://sf.net/projects/jfacedbc" target=_blank>http://sf.net/projects/jfacedbc</A><BR><BR>6、vss plugin<BR>支持集成开发环境中VSS检出检入支持<BR><A href="http://sf.net/projects/vssplugin" target=_blank>http://sf.net/projects/vssplugin</A><BR><BR>7，VE(visual editor),emf,gef插件<BR><BR><BR><BR>Solex<BR>( Free / Testing )<BR>updated:2005-1-23<BR>Version0.5.2b for Eclipse 3.*<BR>Solex is a Web application testing tool built as a plug-in for the Eclipse IDE. It provides functions to record a client session, adjust it according to various parameters and replay it later typically in order to ensure non regression ...<BR><A href="http://sourceforge.net/projects/solex/" target=_blank>http://sourceforge.net/projects/solex/</A><BR><BR><BR>SWT/Swing Designerupdated<BR>( Free and commercial versions / UI )<BR>updated:2005-5-3<BR>Versions 4.0.1 Eclipse 2.0.x, 2.1.x, 3.0.x and 3.1.0 M1-M6<BR>SWT/Swing Designer is a powerful and easy to use two-way Java GUI designer that supports both Eclipse SWT and Sun Swing technology. It is very easy to create Java GUI applications without spend...<BR><A href="http://www.swt-designer.com/" target=_blank>http://www.swt-designer.com/</A><BR><BR><BR>eclipse-tutorialupdated<BR>( N/A / Tutorial )<BR>updated:2005-5-6<BR>tutorial accesible via through an eclipse plugin too. A collection of tutorials which describe how to use Eclipse for Java development. Developing open source Java applications with java.net and Eclipse This HTML tutorial introduces Eclipse and shows how it can be used to develop open source Java...<BR><A href="http://eclipse-tutorial.dev.java.net/" target=_blank>http://eclipse-tutorial.dev.java.net/</A><BR><BR><BR>Exadel Studio -- Free IDE for JSF and Strutsupdated<BR>( Free / Web )<BR>updated:2005-5-8<BR>Version 2.5.1 for Eclipse 3.0.x.<BR>Exadel Studio is a powerful Web application development tool that extends Eclipse functionality allowing developers to fully utilize Rapid Application Development (RAD) techniques. This cost-effective, simplified solution i...<BR><A href="http://www.exadel.com/products_exadelstudio.htm" target=_blank>http://www.exadel.com/products_exadelstudio.htm</A><BR><BR>XmlAuthor<BR>( Free / XML )<BR>updated:2005-5-2<BR>XmlAuthor is a high quality XML editor plug-in for Eclipse 3.1. It provides all of the standard features you would expect to find in an eclipse editor including: - Syntax Highlighting - Error Reporting - Outline View with Navigation Support. - Content Assist XmlAuthor is free for both comme...<BR><A href="http://www.svcdelivery.com/" target=_blank>http://www.svcdelivery.com</A><BR><BR>XMLBuddy<BR>( Free and commercial versions / XML )<BR>updated:2005-1-30<BR>Version 2.0.23<BR>This version provides basic XML editing capabilities, including support for coloring, code assist, outline view, encoding and validation. The download is an Eclipse plugin you can unzip into your plugins folder.<BR><A href="http://www.xmlbuddy.com/" target=_blank>http://www.xmlbuddy.com</A><BR><BR>EclipseUML2<BR>( CPL1.0 / UML )<BR>updated:2005-4-26<BR>Version 1.0.2, and 1.1.0 Integration build (I200504210935) for Eclipse 3.0<BR>The UML2 project (an Eclipse Tools sub-project) is an EMF-based implementation of the UML 2.0 metamodel for the Eclipse platform. The objectives of this project are to provide a useable ...<BR><A href="http://www.eclipse.org/uml2" target=_blank>http://www.eclipse.org/uml2</A><BR><BR>Omondo EclipseUML<BR>( Free for non-commercial use / UML )<BR>updated:2005-4-11<BR>EclipseUML 2.0.0 Studio/Free for Eclipse 3.0.2*<BR>OMONDO EclipseUML will launch the first modeling software offering full native integration with Eclipse and WSAD. As opposed to other UML Vendors who just re-adapt their software, our solution has been develope...<BR><A href="http://www.omondo.com/download/index.html" target=_blank>http://www.omondo.com/download/index.html</A><BR><BR>Sysdeo Eclipse Tomcat Launcher<BR>( Free / Tomcat )<BR>updated:2005-4-30<BR>Version 2.2.1 for Eclipse 2.1.*, Version 3.1 beta for Eclipse 3.0/3.1<BR>Features: - Starting, stopping and restarting Tomcat 5.x, Tomcat 4.x or 3.3 - Registering Tomcat process to Eclipse debugger - Creating or importing a WAR project (wizard can update ser...<BR><A href="http://www.sysdeo.com/eclipse/tomcatPlugin.html" target=_blank>http://www.sysdeo.com/eclipse/tomcatPlugin.html</A><BR><BR>Lomboz<BR>( Free / J2EE development platform )<BR>updated:2005-2-10<BR>R1 Build-20050106 for Eclipse 3.1.x, R2 Build-20050106 for Eclipse 3.0.x, R3 Build-04042004-1 Eclipse 2.1.x<BR>Lomboz is a free Eclipse plugin for J2EE developers. The tool follows a simple principle: "No magic tricks". Lomboz is integrated with many popular op...<BR><A href="http://forge.objectweb.org/projects/lomboz" target=_blank>http://forge.objectweb.org/projects/lomboz</A><BR><BR>Solex<BR>( Free / Testing )<BR>updated:2005-1-23<BR>Version0.5.2b for Eclipse 3.*<BR>Solex is a Web application testing tool built as a plug-in for the Eclipse IDE. It provides functions to record a client session, adjust it according to various parameters and replay it later typically in order to ensure non regression ...<BR><A href="http://sourceforge.net/projects/solex/" target=_blank>http://sourceforge.net/projects/solex/</A><BR><BR>SQLExplorer<BR>( LGPL / Database )<BR>updated:2005-3-29<BR>Version 2.2.3 for eclipse 3.0<BR>SQLExplorer is a database query/schema viewer for nearly any kind of JDBC database. It also supports plugins for specialized functionality for individual databases and data tools ( like Hibernate ) It is fork of the JFace...<BR><A href="http://sourceforge.net/projects/eclipsesql" target=_blank>http://sourceforge.net/projects/eclipsesql</A><BR><BR>DBEdit<BR>( Free for non-commercial use / Database )<BR>updated:2005-4-12<BR>Version 1.0.3.1 for Eclipse 3.0<BR>DbEdit is a set of plugins for the Eclipse Platform that provide viewing, editing and designing capabilities using the JDBCTM API. It is not intended to replace any proprietary database management tool because it surely cannot beat the...<BR><A href="http://sourceforge.net/projects/dbedit" target=_blank>http://sourceforge.net/projects/dbedit</A><BR><BR>Hibernate Synchronizer<BR>( CPL1.0 / Database )<BR>updated:2005-1-28<BR>v2.2.2 for Eclipse 2.1, v3.0.1 for Eclipse 3.x<BR>Hibernate Synchronizer is a free Eclipse plugin code generation tool to be used with the Hibernate persistence framework. The plugin will automatically generate java code wh...<BR><A href="http://hibernatesynch.sourceforge.net/" target=_blank>http://hibernatesynch.sourceforge.net</A><BR><BR>DB Studio<BR>( Free / Database )<BR>updated:2005-3-19<BR>Version 3.1.1<BR>New Version 3.1.1 DB Studio 3.1.1 is now available in 3 formats: * As an Eclipse plugin * As a Stand-Alone Application (pre-packaged with Eclipse) * As part of ThinStructure 3.1.1 DB Studio is an easy-to-use graphical front-end to all databases....<BR><A href="http://www.awoma.com/dbstudio" target=_blank>http://www.awoma.com/dbstudio</A><BR><BR><BR><BR><BR>NRG JavaScript editornew<BR>( Unknown / Languages )<BR>updated:2005-5-8<BR>A simple Javascript editor with syntax highlighting and code completion<BR><A href="http://www.energybyte.com/products/open%20source/" target=_blank>http://www.energybyte.com/products/open%20source/</A><BR><BR>NitroX JSP Editor J2EE development platform (1.0)<BR>FREE NitroX JSP Editor for Eclipse Download: <A href="http://www.m7.com/epiinfo.do" target=_blank>http://www.m7.com/epiinfo.do</A> The NitroX JSP Editor provides the following features: * Professional JSP source editor * Simultaneous 2-way source and visual JSP editors * JSP 2.0 (including EL) - Unequaled! * JSTL * Grapical editor for TLDs * Graphical editor for web.xml * Code completion * Custom tag library support * + much more * and it's FREE! Act now because this offer is available only for a limited time. Thank you, M7 Team<BR>more<BR><BR>NitroX Struts IDE J2EE development platform (0.6663198)<BR>itroX for JSP and Struts - Extends eclipse to the next level in web application development. Debug JSP pages directly. Set break points directly on your JSP pages, step through the actual JSP page. Step into tags, scriplets, etc. Debugging capabilities goes well beyond other environments with support for most application servers. Unique JSP variables view isolates variables for easy access.AppXRay - Scans the web app and provides NitroX the knowledge of all web artifacts so that automatic v...<BR>]]></description>
</item><item>
<title><![CDATA[[转]对VC中有关数据类型转换的整理]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=fishyqd&amp;id=13053</link>
<author>fishyqd</author>
<pubDate>2006/3/30 23:50:27</pubDate>
<description><![CDATA[<A></A>
<TABLE class="fixedTable blogpost" cellSpacing=0 width="100%" border=0>
<TBODY>
<TR>
<TD class=ellipse>
<P><SPAN class=bvTitle id=subjcns!F27CB74CE9ADA6E7!152><STRONG>原文地址：</STRONG>http://spaces.msn.com/wsycqyz/blog/cns!F27CB74CE9ADA6E7!152.trak</SPAN></P>
<P><SPAN class=bvTitle><STRONG>对VC中有关数据类型转换的整理</STRONG></SPAN></P></TD></TR>
<TR>
<TD class=bvh8><STRONG></STRONG></TD></TR>
<TR>
<TD id=msgcns!F27CB74CE9ADA6E7!152>
<DIV>
<P>说明：本文纯粹是总结一下有关类型转换的贴子，</P>
<P>本人并未对所有方法都做测试，仅仅是为了给大家一个参考。</P>
<P>读者层次：<FONT color=#006699>初学</FONT></P>
<P>int i = 100;<BR>long l = 2001;<BR>float f=300.2;<BR>double d=12345.119;<BR>char username[]="程佩君";<BR>char temp[200];<BR>char *buf;<BR>CString str;<BR>_variant_t v1;<BR>_bstr_t v2;<BR><BR><FONT color=#6699ff><B>一、其它数据类型转换为字符串</B></FONT><BR></P>
<UL>
<LI><FONT color=#6699ff>短整型(int)</FONT><BR>itoa(i,temp,10);///将i转换为字符串放入temp中,最后一个数字表示十进制<BR>itoa(i,temp,2); ///按二进制方式转换 
<LI><FONT color=#6699ff>长整型(long)</FONT><BR>ltoa(l,temp,10); 
<LI><FONT color=#6699ff>浮点数(float,double)</FONT><BR>用fcvt可以完成转换,这是MSDN中的例子:<BR>int decimal, sign; <BR>char *buffer; <BR>double source = 3.1415926535; <BR>buffer = _fcvt( source, 7, &amp;decimal, &amp;sign ); <BR>运行结果:source: 3.1415926535 buffer: '31415927' decimal: 1 sign: 0<BR>decimal表示小数点的位置,sign表示符号:0为正数，1为负数 
<LI><FONT color=#6699ff>CString变量</FONT><BR>str = "2008北京奥运";<BR>buf = (LPSTR)(LPCTSTR)str; 
<LI><FONT color=#6699ff>BSTR变量</FONT><BR>BSTR bstrValue = ::SysAllocString(L"程序员"); <BR>char * buf = _com_util::ConvertBSTRToString(bstrValue); <BR>SysFreeString(bstrValue); <BR>AfxMessageBox(buf); <BR>delete(buf); 
<LI><FONT color=#6699ff>CComBSTR变量</FONT><BR>CComBSTR bstrVar("test"); <BR>char *buf = _com_util::ConvertBSTRToString(bstrVar.m_str); <BR>AfxMessageBox(buf); <BR>delete(buf); <BR>
<LI><FONT color=#6699ff>_bstr_t变量</FONT><BR>_bstr_t类型是对BSTR的封装，因为已经重载了=操作符，所以很容易使用<BR>_bstr_t bstrVar("test"); <BR>const char *buf = bstrVar;///不要修改buf中的内容 <BR>AfxMessageBox(buf); <BR><BR>
<LI><FONT color=#6699ff>通用方法(针对非COM数据类型)</FONT><BR>用sprintf完成转换<BR><PRE>char  buffer[200];
char  c = '1';
int   i = 35;
long  j = 1000;
float f = 1.7320534f;
sprintf( buffer, "%c",c);
sprintf( buffer, "%d",i);
sprintf( buffer, "%d",j);
sprintf( buffer, "%f",f);
</PRE></LI></UL>
<P><B><FONT color=#6699ff>二、字符串转换为其它数据类型</FONT></B><BR>strcpy(temp,"123"); </P>
<UL>
<LI><FONT color=#6699ff>短整型(int)</FONT><BR>i = atoi(temp); 
<LI><FONT color=#6699ff>长整型(long)</FONT><BR>l = atol(temp); 
<LI><FONT color=#6699ff>浮点(double)</FONT><BR>d = atof(temp); 
<LI><FONT color=#6699ff>CString变量</FONT><BR>CString name = temp; 
<LI><FONT color=#6699ff>BSTR变量</FONT> <BR>BSTR bstrValue = ::SysAllocString(L"程序员"); <BR>...///完成对bstrValue的使用<BR>SysFreeString(bstrValue); <BR>
<LI><FONT color=#6699ff>CComBSTR变量</FONT><BR>CComBSTR类型变量可以直接赋值<BR>CComBSTR bstrVar1("test");<BR>CComBSTR bstrVar2(temp);<BR>
<LI><FONT color=#6699ff>_bstr_t变量</FONT><BR>_bstr_t类型的变量可以直接赋值<BR>_bstr_t bstrVar1("test"); <BR>_bstr_t bstrVar2(temp); <BR><BR></LI></UL>
<P><B><FONT color=#6699ff>三、其它数据类型转换到CString</FONT></B><BR>使用CString的成员函数Format来转换,例如:<BR></P>
<UL>
<LI>整数(int)<BR>str.Format("%d",i); 
<LI>浮点数(float)<BR>str.Format("%f",i); 
<LI>字符串指针(char *)等已经被CString构造函数支持的数据类型可以直接赋值<BR>str = username; 
<LI>对于Format所不支持的数据类型，可以通过上面所说的关于其它数据类型转化到char *的方法先转到char *，然后赋值给CString变量。<BR></LI></UL>
<P><B><FONT color=#6699ff>四、BSTR、_bstr_t与CComBSTR</FONT></B><BR></P>
<UL>
<LI>CComBSTR 是ATL对BSTR的封装，_bstr_t是C++对BSTR的封装,BSTR是32位指针,但并不直接指向字串的缓冲区。<BR>char *转换到BSTR可以这样: <BR>BSTR b=_com_util::ConvertStringToBSTR("数据");///使用前需要加上comutil.h和comsupp.lib<BR>SysFreeString(bstrValue); <BR>反之可以使用<BR>char *p=_com_util::ConvertBSTRToString(b);<BR>delete p;<BR>具体可以参考一，二段落里的具体说明。<BR><BR>CComBSTR与_bstr_t对大量的操作符进行了重载，可以直接进行=,!=,==等操作，所以使用非常方便。<BR>特别是_bstr_t,建议大家使用它。<BR></LI></UL>
<P><B><FONT color=#6699ff>五、VARIANT 、_variant_t 与 COleVariant</FONT></B><BR></P>
<UL>
<LI>VARIANT的结构可以参考头文件VC98\Include\OAIDL.H中关于结构体tagVARIANT的定义。<BR>对于VARIANT变量的赋值：首先给vt成员赋值，指明数据类型，再对联合结构中相同数据类型的变量赋值，举个例子：<BR>VARIANT va;<BR>int a=2001;<BR>va.vt=VT_I4;///指明整型数据<BR>va.lVal=a; ///赋值<BR><BR>对于不马上赋值的VARIANT，最好先用Void VariantInit(VARIANTARG FAR* pvarg);进行初始化,其本质是将vt设置为VT_EMPTY,下表我们列举vt与常用数据的对应关系:<BR><BR>
<TABLE cellSpacing=1 cellPadding=0 width=792 bgColor=#333333 border=0>
<TBODY>
<TR bgColor=#ffffff>
<TD width=442>Byte bVal; </TD>
<TD width=338>// VT_UI1.</TD></TR>
<TR bgColor=#ffffff>
<TD width=442>Short iVal; </TD>
<TD width=338>// VT_I2.</TD></TR>
<TR bgColor=#ffffff>
<TD width=442>long lVal; </TD>
<TD width=338>// VT_I4.</TD></TR>
<TR bgColor=#ffffff>
<TD width=442>float fltVal; </TD>
<TD width=338>// VT_R4.</TD></TR>
<TR bgColor=#ffffff>
<TD width=442>double dblVal; </TD>
<TD width=338>// VT_R8.</TD></TR>
<TR bgColor=#ffffff>
<TD width=442>VARIANT_BOOL boolVal; </TD>
<TD width=338>// VT_BOOL.</TD></TR>
<TR bgColor=#ffffff>
<TD width=442>SCODE scode; </TD>
<TD width=338>// VT_ERROR.</TD></TR>
<TR bgColor=#ffffff>
<TD width=442>CY cyVal; </TD>
<TD width=338>// VT_CY.</TD></TR>
<TR bgColor=#ffffff>
<TD width=442>DATE date; </TD>
<TD width=338>// VT_DATE.</TD></TR>
<TR bgColor=#ffffff>
<TD width=442>BSTR bstrVal; </TD>
<TD width=338>// VT_BSTR.</TD></TR>
<TR bgColor=#ffffff>
<TD width=442>DECIMAL FAR* pdecVal </TD>
<TD width=338>// VT_BYREF|VT_DECIMAL.</TD></TR>
<TR bgColor=#ffffff>
<TD width=442>IUnknown FAR* punkVal; </TD>
<TD width=338>// VT_UNKNOWN.</TD></TR>
<TR bgColor=#ffffff>
<TD width=442>IDispatch FAR* pdispVal; </TD>
<TD width=338>// VT_DISPATCH.</TD></TR>
<TR bgColor=#ffffff>
<TD width=442>SAFEARRAY FAR* parray; </TD>
<TD width=338>// VT_ARRAY|*.</TD></TR>
<TR bgColor=#ffffff>
<TD width=442>Byte FAR* pbVal; </TD>
<TD width=338>// VT_BYREF|VT_UI1.</TD></TR>
<TR bgColor=#ffffff>
<TD width=442>short FAR* piVal; </TD>
<TD width=338>// VT_BYREF|VT_I2.</TD></TR>
<TR bgColor=#ffffff>
<TD width=442>long FAR* plVal; </TD>
<TD width=338>// VT_BYREF|VT_I4.</TD></TR>
<TR bgColor=#ffffff>
<TD width=442>float FAR* pfltVal; </TD>
<TD width=338>// VT_BYREF|VT_R4.</TD></TR>
<TR bgColor=#ffffff>
<TD width=442>double FAR* pdblVal; </TD>
<TD width=338>// VT_BYREF|VT_R8.</TD></TR>
<TR bgColor=#ffffff>
<TD width=442>VARIANT_BOOL FAR* pboolVal; </TD>
<TD width=338>// VT_BYREF|VT_BOOL.</TD></TR>
<TR bgColor=#ffffff>
<TD width=442>SCODE FAR* pscode; </TD>
<TD width=338>// VT_BYREF|VT_ERROR.</TD></TR>
<TR bgColor=#ffffff>
<TD width=442>CY FAR* pcyVal; </TD>
<TD width=338>// VT_BYREF|VT_CY.</TD></TR>
<TR bgColor=#ffffff>
<TD width=442>DATE FAR* pdate; </TD>
<TD width=338>// VT_BYREF|VT_DATE.</TD></TR>
<TR bgColor=#ffffff>
<TD width=442>BSTR FAR* pbstrVal; </TD>
<TD width=338>// VT_BYREF|VT_BSTR.</TD></TR>
<TR bgColor=#ffffff>
<TD width=442>IUnknown FAR* FAR* ppunkVal; </TD>
<TD width=338>// VT_BYREF|VT_UNKNOWN.</TD></TR>
<TR bgColor=#ffffff>
<TD width=442>IDispatch FAR* FAR* ppdispVal; </TD>
<TD width=338>// VT_BYREF|VT_DISPATCH.</TD></TR>
<TR bgColor=#ffffff>
<TD width=442>SAFEARRAY FAR* FAR* pparray; </TD>
<TD width=338>// VT_ARRAY|*.</TD></TR>
<TR bgColor=#ffffff>
<TD width=442>VARIANT FAR* pvarVal; </TD>
<TD width=338>// VT_BYREF|VT_VARIANT.</TD></TR>
<TR bgColor=#ffffff>
<TD width=442>void FAR* byref; </TD>
<TD width=338>// Generic ByRef.</TD></TR>
<TR bgColor=#ffffff>
<TD width=442>char cVal; </TD>
<TD width=338>// VT_I1.</TD></TR>
<TR bgColor=#ffffff>
<TD width=442>unsigned short uiVal; </TD>
<TD width=338>// VT_UI2.</TD></TR>
<TR bgColor=#ffffff>
<TD width=442>unsigned long ulVal; </TD>
<TD width=338>// VT_UI4.</TD></TR>
<TR bgColor=#ffffff>
<TD width=442>int intVal; </TD>
<TD width=338>// VT_INT.</TD></TR>
<TR bgColor=#ffffff>
<TD width=442>unsigned int uintVal; </TD>
<TD width=338>// VT_UINT.</TD></TR>
<TR bgColor=#ffffff>
<TD width=442>char FAR * pcVal; </TD>
<TD width=338>// VT_BYREF|VT_I1.</TD></TR>
<TR bgColor=#ffffff>
<TD width=442>unsigned short FAR * puiVal; </TD>
<TD width=338>// VT_BYREF|VT_UI2.</TD></TR>
<TR bgColor=#ffffff>
<TD width=442>unsigned long FAR * pulVal; </TD>
<TD width=338>// VT_BYREF|VT_UI4.</TD></TR>
<TR bgColor=#ffffff>
<TD width=442>int FAR * pintVal; </TD>
<TD width=338>// VT_BYREF|VT_INT.</TD></TR>
<TR bgColor=#ffffff>
<TD width=442>unsigned int FAR * puintVal; </TD>
<TD width=338>//VT_BYREF|VT_UINT.</TD></TR></TBODY></TABLE><BR>
<LI>_variant_t是VARIANT的封装类，其赋值可以使用强制类型转换，其构造函数会自动处理这些数据类型。<BR>使用时需加上#include &lt;comdef.h&gt;<BR>例如：<BR>long l=222;<BR>ing i=100;<BR>_variant_t lVal(l);<BR>lVal = (long)i;<BR><BR>
<LI>COleVariant的使用与_variant_t的方法基本一样，请参考如下例子：<BR>COleVariant v3 = "字符串", v4 = (long)1999;<BR>CString str =(BSTR)v3.pbstrVal;<BR>long i = v4.lVal;<BR><BR></LI></UL>
<P><FONT color=#6699ff><B>六、其它一些COM数据类型</B></FONT></P>
<UL>
<LI>根据ProgID得到CLSID<BR>HRESULT CLSIDFromProgID( LPCOLESTR lpszProgID,LPCLSID pclsid);<BR>CLSID clsid;<BR>CLSIDFromProgID( L"MAPI.Folder",&amp;clsid);<BR>
<LI>根据CLSID得到ProgID<BR>WINOLEAPI ProgIDFromCLSID( REFCLSID clsid,LPOLESTR * lplpszProgID); <BR>例如我们已经定义了 CLSID_IApplication,下面的代码得到ProgID<BR>LPOLESTR pProgID = 0;<BR>ProgIDFromCLSID( CLSID_IApplication,&amp;pProgID);<BR>...///可以使用pProgID <BR>CoTaskMemFree(pProgID);//不要忘记释放 <BR></LI></UL>
<P><FONT color=#6699ff><B>七、ANSI与Unicode<BR></B></FONT>Unicode称为宽字符型字串,COM里使用的都是Unicode字符串。</P>
<UL>
<LI>将ANSI转换到Unicode<BR>(1)通过L这个宏来实现，例如: CLSIDFromProgID( L"MAPI.Folder",&amp;clsid);<BR>(2)通过MultiByteToWideChar函数实现转换,例如:<BR>char *szProgID = "MAPI.Folder";<BR>WCHAR szWideProgID[128];<BR>CLSID clsid;<BR>long lLen = MultiByteToWideChar(CP_ACP,0,szProgID,strlen(szProgID),szWideProgID,sizeof(szWideProgID));<BR>szWideProgID[lLen] = '\0'; <BR>(3)通过A2W宏来实现,例如: <BR>USES_CONVERSION; <BR>CLSIDFromProgID( A2W(szProgID),&amp;clsid); 
<LI>将Unicode转换到ANSI<BR>(1)使用WideCharToMultiByte,例如:<BR>// 假设已经有了一个Unicode 串 wszSomeString... <BR>char szANSIString [MAX_PATH]; <BR>WideCharToMultiByte ( CP_ACP, WC_COMPOSITECHECK, wszSomeString, -1, szANSIString, sizeof(szANSIString), NULL, NULL ); <BR>(2)使用W2A宏来实现,例如:<BR>USES_CONVERSION;<BR>pTemp=W2A(wszSomeString); </LI></UL>
<P><FONT color=#6699ff><B>八、其它</B></FONT></P>
<UL>
<LI>对消息的处理中我们经常需要将WPARAM或LPARAM等32位数据（DWORD)分解成两个16位数据（WORD),例如：<BR>LPARAM lParam;<BR>WORD loValue = LOWORD(lParam);///取低16位<BR>WORD hiValue = HIWORD(lParam);///取高16位<BR><BR>
<LI>对于16位的数据(WORD)我们可以用同样的方法分解成高低两个8位数据(BYTE),例如:<BR>WORD wValue;<BR>BYTE loValue = LOBYTE(wValue);///取低8位<BR>BYTE hiValue = HIBYTE(wValue);///取高8位<BR><BR>
<LI>两个16位数据（WORD）合成32位数据(DWORD,LRESULT,LPARAM,或WPARAM)<BR>LONG MAKELONG( WORD wLow, WORD wHigh );<BR>WPARAM MAKEWPARAM( WORD wLow, WORD wHigh ); <BR>LPARAM MAKELPARAM( WORD wLow, WORD wHigh );<BR>LRESULT MAKELRESULT( WORD wLow, WORD wHigh ); <BR><BR>
<LI>两个8位的数据(BYTE)合成16位的数据(WORD)<BR>WORD MAKEWORD( BYTE bLow, BYTE bHigh ); <BR><BR>
<LI>从R(red),G(green),B(blue)三色得到COLORREF类型的颜色值<BR>COLORREF RGB( BYTE byRed,BYTE byGreen,BYTE byBlue );<BR>例如COLORREF bkcolor = RGB(0x22,0x98,0x34);<BR><BR>
<LI>从COLORREF类型的颜色值得到RGB三个颜色值<BR>BYTE Red = GetRValue(bkcolor); ///得到红颜色<BR>BYTE Green = GetGValue(bkcolor); ///得到绿颜色<BR>BYTE Blue = GetBValue(bkcolor); ///得到兰颜色<BR></LI></UL>
<P><FONT color=#6699ff><B>九、注意事项</B></FONT><BR>假如需要使用到ConvertBSTRToString此类函数,需要加上头文件comutil.h,并在setting中加入comsupp.lib或者直接加上#pragma comment( lib, "comsupp.lib" )</P>
<P>后记：本文匆匆写成，错误之处在所难免，欢迎指正.<BR></P>
<P><FONT color=#0033cc>关于把BSTR类型数据转换成CString 类型数据时的问题</FONT><FONT color=#666666>?</FONT><BR>当我在把BSTR类型数据转换成CString 或 “char* 类型”数据时，发现在BSTR类型字符串较短的情况下没问题，当较长时就会出现<BR>内存读写错了。（在NT，2000下都测试是这样的。）<BR>根据你所说：<BR>1）字符串指针(char *)等已经被CString构造函数支持的数据类型 可以直接赋值 str = username;<BR>2）当b 为BSTR类型时可以使用<BR>char *p=_com_util::ConvertBSTRToString(b);<BR>于是以下是对的：<BR>CString cstr;<BR>BSTR bstr;<BR>....<BR>cstr=com_util::ConvertBSTRToString(bstr);<BR>...<BR>可是当bstr非常大时（其实，较大时就会）就会出现内存读写错，不知何故。<BR>此外我发现cstr=com_util::ConvertBSTRToString(bstr);<BR>可以简化为 cstr=bstr; 但当bstr较大时同样出现这个问题。<BR>请兄弟帮忙！急。谢谢！</P><FONT color=#0033cc>如何转化((list*)fileip.bian)-&gt;liang<BR></FONT>
<P><FONT color=#0033cc>关于把CString转化成LPCTSTR的问题</FONT><FONT color=#666666> 作者:jakiesun 发表日期:2001-9-5 20:08:48</FONT><BR>我记的我以前写过这样一段代码<BR>void function()<BR>{<BR>CString str,str1,str2;<BR>function((char*)(LPCTSTR)str1);<BR>str=str1;<BR>...//调试道此发现str2的值随着str的改变而改变，请问能解释一下为什么，如有回答，请通知<BR>wangshaohong@sohu.com,tx先<BR><BR>}</P>
<P><FONT color=#0033cc>添加lib支持</FONT><FONT color=#666666> 作者:磨刀霍霍 发表日期:2001-9-10 11:32:12</FONT><BR>如果不添加会产生错误，在setting中加入comsupp.lib或者直接#pragma comment( lib, "comsupp.lib" )<BR>微软认为缺省的设置call convention如果不设置成__cdecl也会出现同样的错误。</P>
<P><BR><FONT color=#0033cc>1。int 转成cstring ？？<BR></FONT><BR>回复人：　caigzhi(caigzhi)　(2001-10-17 11:27:35) 得0分&nbsp;<BR>CString 的成员函数Format()<BR><BR>int a = 2131;<BR>CString str;<BR>str.Format("%d",a);<BR><BR>回复人：　tenchi(C与C++之间)　(2001-10-17 11:32:12) 得0分&nbsp;<BR>int i=2001;<BR>char str[10];<BR>_itoa(i,str,10);<BR>CString szString=str;&nbsp;<BR>回复人：　fiolin(幽深的水)　(2001-10-17 11:45:40) 得0分&nbsp;<BR>他们两个的都可以！！&nbsp;<BR><BR>回复人：　sohucsdnvc(thanks)　(2001-10-17 13:24:17) 得0分&nbsp;<BR>那如何把double转成cstring&nbsp;<BR>回复人：　yihugang(小虎子)　(2001-10-17 13:29:15) 得6分&nbsp;<BR>int i = 2131;<BR>char *c=new char[20];<BR>CString str;<BR>sprintf(c,'%d',i);<BR>str=*c;<BR><BR><BR>回复人：　Gu_c_h(Gu)　(2001-10-17 14:07:17) 得0分&nbsp;<BR>用 _gcvt 下面是 msdn 的例子<BR><BR>Example<BR><BR>/* _GCVT.C: This program converts -3.1415e5<BR>* to its string representation.<BR>*/<BR><BR>#include &lt;stdlib.h&gt;<BR>#include &lt;stdio.h&gt;<BR><BR>void main( void )<BR>{<BR>char buffer[50];<BR>double source = -3.1415e5;<BR>_gcvt( source, 7, buffer );<BR>printf( "source: %f buffer: '%s'\n", source, buffer );<BR>_gcvt( source, 7, buffer );<BR>printf( "source: %e buffer: '%s'\n", source, buffer );<BR>}<BR><BR><BR>Output<BR><BR>source: -314150.000000 buffer: '-314150.'<BR>source: -3.141500e+005 buffer: '-314150.'<BR><BR>回复人：　Gu_c_h(Gu)　(2001-10-17 14:49:56) 得6分&nbsp;<BR>int a = -3.1415e5;<BR>CString str;<BR>str.Format("%f",a);&nbsp;<BR>回复人：　ruixp(锐剑)　(2001-10-17 15:06:48) 得6分&nbsp;<BR>CString 的成员函数Format()<BR>int a = 2131;<BR>CString str;<BR>str.Format("%d",a);<BR><BR><FONT color=#0033cc>2。基类对象怎么能转换成派生类对象？<BR></FONT>int CDaoListView::OnCreate(LPCREATESTRUCT lpCreateStruct)&nbsp;<BR>{<BR>lpCreateStruct-&gt;style |= LVS_REPORT |LVS_EDITLABELS;<BR>if (CListView::OnCreate(lpCreateStruct) == -1)<BR>return -1;<BR><BR>//////////// 创建ImageList;<BR>CDaoViewApp * pApp = (CDaoViewApp *) AfxGetApp();<BR><BR>m_pImageList = new CImageList();<BR>ASSERT(m_pImageList !=NULL);<BR>m_pImageList-&gt;Create(16,16,TRUE,4,4);<BR>m_pImageList-&gt;Add(pApp-&gt;LoadIcon(IDI_KEY));<BR>m_pImageList-&gt;Add(pApp-&gt;LoadIcon(IDI_ICON4));<BR>m_pImageList-&gt;Add(pApp-&gt;LoadIcon(IDI_ICON5));<BR><BR>CListCtrlEx&amp; ctlList = (CListCtrlEx&amp;) GetListCtrl();//我不懂的就这句，cListCtrlEx看下面的声明。<BR>ctlList.SetImageList (m_pImageList, LVSIL_SMALL) ;<BR>////////////<BR>return 0;<BR>}<BR><BR>class CListCtrlEx : public CListCtrl//类cListCtrlEx定义。<BR>{.....<BR>}<BR>class CDaoListView : public CListView//cDaoListView定义！<BR>{<BR>...<BR>}<BR>注：我的问题是GetListCtrl()返回的是一个cListCtrl对象的引用,怎么能把它转换成一个它的派生类对象的引用？c++的类型转换怎么支持？&nbsp;<BR><BR><BR>回复贴子：&nbsp;<BR>回复人：　lhj(努力加油)　(2002-1-29 18:56:06) 得0分&nbsp;<BR>CListCtrlEx&amp; ctlList = (CListCtrlEx&amp;) GetListCtrl();<BR>这是强制类型转换，&amp;表示是一个引用，lctList的值在这次赋值后不能被修改。<BR><BR>回复人：　wwwsq(wwwsq)　(2002-1-29 19:09:22) 得0分&nbsp;<BR>建议你找本C++方面的书看看，VC虽然号称可视，实际上C++基础还是很重要的。<BR><BR><BR>回复人：　xcopy(xcopy)　(2002-1-29 19:26:16) 得0分&nbsp;<BR>用dynamic_cast()可以安全的转换。&nbsp;<BR><BR><FONT color=#0033cc>3。如何在CString和double之间转换？要求转换之后能保留小数点，保留正负号？？<BR></FONT><BR>cstring::format(%.xe) x为精度位&nbsp;<BR><BR>回复人：　pchaos(杂讲)　(2002-1-28 11:21:46) 得0分&nbsp;<BR>CString str;<BR>double db;<BR>str = "123.456";<BR>db = atof((LPCTSTR)str);&nbsp;<BR>回复人：　hgw111(hg)　(2002-1-28 11:52:57) 得0分&nbsp;<BR>CString -&gt; double : atof<BR>double -&gt;CString :Format&nbsp;<BR>回复人：　pchaos(杂讲)　(2002-1-28 13:46:04) 得0分&nbsp;<BR>CString str;<BR>double db;<BR>str = "123.456";<BR>db = atof((LPCTSTR)str);&nbsp;<BR>db = 777.999;<BR>str.format("%e", db);&nbsp;<BR><BR><FONT color=#0033cc>4。字符型要转换成int？？<BR></FONT>atoi(str)&nbsp;<BR><BR><FONT color=#0033cc>5。_bstr_t 到 unsigned int？？<BR></FONT>_bstr_t str;<BR>unsigned int Length=6;<BR>Length=Length-str.length();&nbsp;<BR><BR><FONT color=#0033cc>6。VARIANT类型转换问题？<BR></FONT>我在使用MSCOMM中SetOutput()函数时<BR>形参必须为VARIANT变量<BR>如何将其它的数据类型转换为VARIANT类型？<BR>如：Cstring-&gt;VARIANT、 *char-&gt;VARIANT<BR>我对VARIANT的类型结构体不太熟，请讲详细些（最好有范例），谢谢！<BR><BR>回复贴子：&nbsp;<BR>回复人：　vc_xiaoxin(小新)　(2001-12-26 15:43:57) 得0分&nbsp;<BR>VARIANT本身是一个复杂的结构，别的数据怎么转呀？关注&nbsp;<BR>回复人：　mpg_liu(星仁)　(2001-12-27 18:33:50) 得10分&nbsp;<BR>定义一个VARIANT变量后，他应该是一个结构体变量，其中有一个成员是字符型的，给这个成员赋值&nbsp;<BR>回复人：　LLnju(LLnju)　(2001-12-27 18:36:10) 得0分&nbsp;<BR>实在不清楚嘛就用 _variant_t , COleVariant 这些东东嘛，很好用的啊&nbsp;<BR>回复人：　softarts(CDMA2000)　(2001-12-27 18:41:32) 得10分&nbsp;<BR>构造一个就行了。<BR>VARIANT varXX;<BR>CString strYY;<BR>varXX.vt=VT_BSTR;<BR>varXX.bstrVal = strYY.allocsysstring();<BR>应该可以了。<BR>回复人：　softarts(CDMA2000)　(2001-12-27 18:42:11) 得0分&nbsp;<BR>我也觉得COleVariant要好用一些，呵呵，我都用它。&nbsp;<BR>回复人：　bobofu(有问题要问)　(2001-12-27 19:32:18) 得10分&nbsp;<BR>CString str;<BR>_variant_t var;<BR>var = _variant_t(str);&nbsp;<BR><BR><FONT color=#0033cc>7。COleVarant 如何转换为 CString?<BR></FONT>CString 如何转换为 char *<BR>CString 如何转换为 char[xx] ？？<BR><BR>CString 如何转换为 char * wsprintf或者＝<BR>CString 如何转换为 char[xx] strcpy（）&nbsp;<BR>回复人：　SecretGarden(天堂鸟)　(2002-1-14 11:55:23) 得0分&nbsp;<BR>COleVarant封装了VAREANT类型。<BR>VAREANT类型其实是个巨大地Union，里面自然有你<BR>想要地unsigned char *类型。<BR>CString地GetBuffer和Format可以实现你的后两个问题<BR><BR><BR><FONT color=#0033cc>8。v_variant_t类型转换成cstring<BR></FONT>总提示我cstring未定义<BR>程序如下<BR>_variant_t vfirstname;//存储的是数据库中的数据<BR>CString str;//提示出错<BR>vfirstname=pRs-&gt;GetCollect (_variant_t("Phone_Num"));<BR>vfirstname.ChangeType (VT_BSTR);<BR>str=vfirstname.bstrVal;//提示出错&nbsp;<BR><BR><BR>回复贴子：&nbsp;<BR>回复人：　hydnoahark(诺亚方舟)　(2001-11-12 11:56:51) 得10分&nbsp;<BR>&gt;&gt;CString str;//提示出错<BR>要求include &lt;afx.h&gt;并且设置Use run-time Library为Multithreaded&nbsp;<BR>回复人：　zhengyun_ustc(^-^)　(2001-11-12 12:04:39) 得15分&nbsp;<BR>CString未定义，说明你的工程没有引用MFC！！<BR><BR>要想使你的工程支持MFC，请按照以下步骤作：<BR>1：在你的stdafx.h的头文件中加入：<BR>#include "afxtempl.h"<BR>这是一个囊括了MFC的集合定义的头文件，有了它，你的工程就识别Cstring类了。<BR><BR>2：在你的工程设置中，在General页中，选择“MFC”为“Using MFC in a shared DLL”<BR><BR>OK，现在再编译你的工程即可。&nbsp;<BR>回复人：　zhengyun_ustc(^-^)　(2001-11-12 12:06:56) 得5分&nbsp;<BR>_variant_t的bstrVal成员是BSTR类型。<BR>它是一个指向一个OLECHART*的指针。&nbsp;<BR>回复人：　vickowang(小苍)　(2001-11-12 12:48:21) 得5分&nbsp;<BR>(char *)_bstr_t(vfirstname)&nbsp;<BR>回复人：　smallfool(smallfool)　(2001-11-12 13:52:54) 得4分&nbsp;<BR>或许你还需要一个从UNICODE字符到ANSI字符的转变函数&nbsp;<BR>回复人：　sun_1112(萧)　(2001-11-12 17:34:44) 得0分&nbsp;<BR>谢谢大家<BR>给我这么大的支持！：）&nbsp;<BR>回复人：　zhengyun_ustc(^-^)　(2001-11-14 13:24:07) 得0分&nbsp;<BR>用vickowang(小苍)的意见可能会有问题，转换出的字符串应该是乱码。<BR><BR>因为(char *)转换需要一个const的字符串资源，才能强制转换。<BR>所以应该：<BR>_bstr_t bstrTemp = _bstr_t(vfirstname.bstrVal);<BR>TCHAR szTemp[MAX_PATH];<BR>szTemp = (char*)bstrTemp;<BR><BR><FONT color=#0033cc>9。char * 转换为TCHAR类型？？<BR></FONT>直接转换,TCHAR相当于char了<BR>char * s;<BR>TCHAR * s1=(TCHAR *)s;&nbsp;<BR>回复人：　dysxq()　(2001-12-21 21:26:25) 得0分&nbsp;<BR>要看你的程序设置是ANSI还是UNICODE, 如果是ANSI,直接转,如果是UNICODE,TCHAR相当于WCHAR, 要用mbstowcsz转一下&nbsp;<BR>回复人：　xiaoxiaohan(萧晓寒)　(2001-12-21 23:52:17) 得0分&nbsp;<BR>Unicode ：宽字节字符集<BR>1. 如何取得一个既包含单字节字符又包含双字节字符的字符串的字符个数？<BR>可以调用Microsoft Visual C++的运行期库包含函数_mbslen来操作多字节（既包括单字节也包括双字节）字符串。<BR>调用strlen函数，无法真正了解字符串中究竟有多少字符，它只能告诉你到达结尾的0之前有多少个字节。<BR>2. 如何对DBCS（双字节字符集）字符串进行操作？<BR>函数 描述<BR>PTSTR CharNext （ LPCTSTR ）; 返回字符串中下一个字符的地址<BR>PTSTR CharPrev （ LPCTSTR, LPCTSTR ）； 返回字符串中上一个字符的地址<BR>BOOL IsDBCSLeadByte( BYTE )； 如果该字节是DBCS字符的第一个字节，则返回非0值<BR>3. 为什么要使用Unicode？<BR>（1） 可以很容易地在不同语言之间进行数据交换。<BR>（2） 使你能够分配支持所有语言的单个二进制.exe文件或DLL文件。<BR>（3） 提高应用程序的运行效率。<BR>Windows 2000是使用Unicode从头进行开发的，如果调用任何一个Windows函数并给它传递一个ANSI字符串，那么系统首先要将字符串转换成<BR>Unicode，然后将Unicode字符串传递给操作系统。如果希望函数返回ANSI字符串，系统就会首先将Unicode字符串转换成ANSI字符串，然后将结<BR>果返回给你的应用程序。进行这些字符串的转换需要占用系统的时间和内存。通过从头开始用Unicode来开发应用程序，就能够使你的应用程序<BR>更加有效地运行。<BR>Windows CE 本身就是使用Unicode的一种操作系统，完全不支持ANSI Windows函数<BR>Windows 98 只支持ANSI，只能为ANSI开发应用程序。<BR>Microsoft公司将COM从16位Windows转换成Win32时，公司决定需要字符串的所有COM接口方法都只能接受Unicode字符串。<BR>4. 如何编写Unicode源代码？<BR>Microsoft公司为Unicode设计了WindowsAPI，这样，可以尽量减少代码的影响。实际上，可以编写单个源代码文件，以便使用或者不使用<BR>Unicode来对它进行编译。只需要定义两个宏（UNICODE和_UNICODE），就可以修改然后重新编译该源文件。<BR>_UNICODE宏用于C运行期头文件，而UNICODE宏则用于Windows头文件。当编译源代码模块时，通常必须同时定义这两个宏。<BR>5. Windows定义的Unicode数据类型有哪些？<BR>数据类型 说明<BR>WCHAR Unicode字符<BR>PWSTR 指向Unicode字符串的指针<BR>PCWSTR 指向一个恒定的Unicode字符串的指针<BR>对应的ANSI数据类型为CHAR，LPSTR和LPCSTR。<BR>ANSI/Unicode通用数据类型为TCHAR，PTSTR,LPCTSTR。<BR>6. 如何对Unicode进行操作？<BR>字符集 特性 实例<BR>ANSI 操作函数以str开头 strcpy<BR>Unicode 操作函数以wcs开头 wcscpy<BR>MBCS 操作函数以_mbs开头 _mbscpy<BR>ANSI/Unicode 操作函数以_tcs开头 _tcscpy（C运行期库）<BR>ANSI/Unicode 操作函数以lstr开头 lstrcpy（Windows函数）<BR>所有新的和未过时的函数在Windows2000中都同时拥有ANSI和Unicode两个版本。ANSI版本函数结尾以A表示；Unicode版本函数结尾以W表示。<BR>Windows会如下定义：<BR>#ifdef UNICODE<BR>#define CreateWindowEx CreateWindowExW<BR>#else<BR>#define CreateWindowEx CreateWindowExA<BR>#endif // !UNICODE<BR>7. 如何表示Unicode字符串常量？<BR>字符集 实例<BR>ANSI “string”<BR>Unicode L“string”<BR>ANSI/Unicode T(“string”)或_TEXT(“string”)if( szError[0] == _TEXT(‘J’) ){ }<BR>8. 为什么应当尽量使用操作系统函数？<BR>这将有助于稍稍提高应用程序的运行性能，因为操作系统字符串函数常常被大型应用程序比如操作系统的外壳进程Explorer.exe所使用。由于<BR>这些函数使用得很多，因此，在应用程序运行时，它们可能已经被装入RAM。<BR>如：StrCat，StrChr，StrCmp和StrCpy等。<BR>9. 如何编写符合ANSI和Unicode的应用程序？<BR>（1） 将文本串视为字符数组，而不是chars数组或字节数组。<BR>（2） 将通用数据类型（如TCHAR和PTSTR）用于文本字符和字符串。<BR>（3） 将显式数据类型（如BYTE和PBYTE）用于字节、字节指针和数据缓存。<BR>（4） 将TEXT宏用于原义字符和字符串。<BR>（5） 执行全局性替换（例如用PTSTR替换PSTR）。<BR>（6） 修改字符串运算问题。例如函数通常希望在字符中传递一个缓存的大小，而不是字节。这意味着不应该传递sizeof(szBuffer),而应该传<BR>递（sizeof(szBuffer)/sizeof(TCHAR)。另外，如果需要为字符串分配一个内存块，并且拥有该字符串中的字符数目，那么请记住要按字节来<BR>分配内存。这就是说，应该调用malloc(nCharacters *sizeof(TCHAR)),而不是调用malloc(nCharacters)。<BR>10. 如何对字符串进行有选择的比较？<BR>通过调用CompareString来实现。<BR>标志 含义<BR>NORM_IGNORECASE 忽略字母的大小写<BR>NORM_IGNOREKANATYPE 不区分平假名与片假名字符<BR>NORM_IGNORENONSPACE 忽略无间隔字符<BR>NORM_IGNORESYMBOLS 忽略符号<BR>NORM_IGNOREWIDTH 不区分单字节字符与作为双字节字符的同一个字符<BR>SORT_STRINGSORT 将标点符号作为普通符号来处理<BR>11. 如何判断一个文本文件是ANSI还是Unicode？<BR>判断如果文本文件的开头两个字节是0xFF和0xFE，那么就是Unicode，否则是ANSI。<BR>12. 如何判断一段字符串是ANSI还是Unicode？<BR>用IsTextUnicode进行判断。IsTextUnicode使用一系列统计方法和定性方法，以便猜测缓存的内容。由于这不是一种确切的科学方法，因此&nbsp;<BR>IsTextUnicode有可能返回不正确的结果。<BR>13. 如何在Unicode与ANSI之间转换字符串？<BR>Windows函数MultiByteToWideChar用于将多字节字符串转换成宽字符串；函数WideCharToMultiByte将宽字符串转换成等价的多字节字符串。<BR><BR>回复人：　xtky_limi(痛在心中笑在脸上)　(2001-12-22 0:35:58) 得0分&nbsp;<BR>上面说的已经比较全了。&nbsp;<BR>回复人：　xtky_limi(痛在心中笑在脸上)　(2001-12-22 0:38:13) 得0分&nbsp;<BR>TEXT是宏<BR>相当于L##<BR><BR>它可以根据编译环境确定为DBMS,还是UNICODE字符集<BR><BR><FONT color=#0033cc>10。int类型转换为CString类型？</FONT><BR>回复人：　tjmxf(天涯)　(2001-12-17 19:59:34) 得0分&nbsp;<BR>itoa()&nbsp;<BR>回复人：　zf925(天下哪来那么多高手)　(2001-12-17 20:00:30) 得22分&nbsp;<BR>char m[20];<BR>str=str + itoa(i,m,10);&nbsp;<BR>回复人：　yuezifeng(wybzd)　(2001-12-17 20:00:50) 得22分&nbsp;<BR>CString str;<BR>str.Format("%d",i);<BR><BR>回复人：　kingfish(今飞)　(2001-12-17 20:06:27) 得0分&nbsp;<BR>str.Format("%s%d",str,i);&nbsp;<BR>回复人：　tanyajun(谈子)　(2001-12-17 20:09:25) 得0分&nbsp;<BR>CString str="test";<BR>int i=11;<BR>CString str1;<BR>str1.Format("%d",i);<BR>str = str+str1;<BR><BR>回复人：　guanjinke(纶巾客)　(2001-12-17 20:10:42) 得0分&nbsp;<BR>int i=11;<BR>CString str="test";<BR>CString addition;<BR>addition.Format("%d",i);<BR>str+=addition;<BR>就可以了。&nbsp;<BR><BR><FONT color=#0033cc>11。关于sprintf类型转换的问题</FONT><BR>sprintf(buf,"select price from ls01 where p_date&gt;='%'",t_date)<BR>其中t_date是CTime类型，%后面应该是什么呢？%s是String类型,%c是char,那么CTime型对应的是什么呢？&nbsp;<BR>&nbsp;<BR>回复人：　yakai(日落长河)　(2001-12-17 17:45:47) 得0分&nbsp;<BR>sprintf(buf,"select price from ls01 where p_date&gt;='%S'",(LPCSTR)t_date.Format( "%A, %B %d, %Y" ));<BR>如果不行，就<BR>char temp[50];<BR>CString str=t_date.Format( "%A, %B %d, %Y" );<BR>strcpy(temp,(LPCSTR)str);<BR>sprintf(buf,"select price from ls01 where p_date&gt;='%S'",temp);<BR>CTime::Format返回CString&nbsp;<BR>回复人：　loh(乐啸天涯)　(2001-12-17 17:52:57) 得0分&nbsp;<BR>wait<BR><BR>don't know&nbsp;<BR>回复人：　masterz()　(2001-12-17 20:21:05) 得0分&nbsp;<BR>SQL语句中日期要写成字符串"yyyymmdd"&nbsp;<BR><BR><BR><FONT color=#0033cc>12。类型转换 unsigned int &lt;==&gt;CString??</FONT><BR>回复次数：8<BR>发表时间：2001-12-17 10:25:23<BR><BR>unsigned int f;//unsigned int 0~4294967295<BR>CString g;<BR>f=2300000000;<BR>g.Format("%d",f);<BR>AfxMessageBox(g);<BR>出错。&nbsp; </P>
<P><BR>回复人：　ydogg(灰毛兔频频)　(2001-12-17 10:31:29) 得0分&nbsp;<BR>unsigned int f;//unsigned int 0~4294967295<BR>CString g;<BR>f=2300000000;<BR>g.Format("%d",f);<BR>MessageBox(g);//使用AfxMessageBox，需要窗口的句炳参数<BR><BR>回复人：　asdmusic8(asdmusic8)　(2001-12-17 10:35:15) 得0分&nbsp;<BR>我 AfxMessageBox(g); 和MessageBox(g); 都不错。<BR>错的是g.从 2300000000=》1994967296<BR><BR>回复人：　asdmusic8(asdmusic8)　(2001-12-17 10:36:10) 得0分&nbsp;<BR>是2300000000=》-1994967296 类型转换错。<BR><BR>回复人：　ydogg(灰毛兔频频)　(2001-12-17 10:37:54) 得6分&nbsp;<BR>g.Format("%u",f);<BR><BR>回复人：　asdmusic8(asdmusic8)　(2001-12-17 10:40:24) 得0分&nbsp;<BR>to dgsnmpoperate 那怎么从 CString ==&gt;&gt;unsigned int&nbsp;<BR>回复人：　kingfish(今飞)　(2001-12-17 10:42:10) 得6分&nbsp;<BR>既然是 unsigned int,<BR>超过 0x7f000000 (2130706432) 当然不能用 %d (signed int)用%u&nbsp;<BR>回复人：　kingfish(今飞)　(2001-12-17 10:44:57) 得8分&nbsp;<BR>CString ==&gt;&gt;unsigned int&nbsp; <BR>char *p = (LPSTR)(LPCSTR) g;<BR>f = atoi(p);&nbsp;<BR><BR><FONT color=#0033cc>13。static_cast、dynamic_cast 和直接类型转换（如 (void *)p ）的区别?</FONT><BR>发表时间：2001-12-14 9:31:13<BR><BR>先拷贝MSDN中的一小段话：<BR>class B { ... };<BR>class C : public B { ... };<BR>class D : public C { ... };<BR><BR>void f(D* pd)<BR>{<BR>C* pc = dynamic_cast&lt;C*&gt;(pd); // ok: C is a direct base class<BR>// pc points to C subobject of pd&nbsp;<BR><BR>B* pb = dynamic_cast&lt;B*&gt;(pd); // ok: B is an indirect base class<BR>// pb points to B subobject of pd&nbsp;<BR>...<BR>}<BR>我已经知道 static_cast 和 dynamic_cast 的作用，但MSDN中并没有提到这两个操作符与直接类型转换如<BR>void f(D* pd)<BR>{<BR>C* pc = （C*）(pd);<BR><BR>B* pb = （B*）(pd);&nbsp;<BR>...<BR>}<BR>的不同啊。不知道那位知道的告诉一声，在此不胜感谢，50分奉上。<BR><BR>回复贴子：ysdesigned(清泉)　(2001-12-14 10:03:07) 得0分&nbsp;<BR>static_cast、dynamic_cast 代 替 简 单 的 强 制 转 化， 从 而 消 除 多 继 承 带 来 的 歧 义。 使 用 这 两 个 运 算 符 号， 我&nbsp;们可以 在 对 象 运 行 过 程 中 获 取 对 象 的 类 型 信 息<BR>dynamic_cast 用于多态类型的转换<BR>static_cast 用于非多态类型的转换<BR><BR>回复人：　masterz()　(2001-12-14 10:05:48) 得0分&nbsp;<BR>static_cast&lt;...&gt;compile时能发现不正确的指针类型转换<BR>dynamic_cast&lt;...&gt;运行时如果发现是不正确的指针类型转换会返回NULL<BR>(void*)强制转换，如果是不正确的指针类型转换，没有办法检查，不如上面2中安全&nbsp;<BR>回复人：　meady()　(2001-12-14 11:29:05) 得0分&nbsp;<BR>类型安全&nbsp;<BR>回复人：　bluecrest(为什么我的VC还是那么的菜)　(2001-12-14 11:45:34) 得0分&nbsp;<BR>com技术内幕介绍过<BR>我刚看完就忘了&nbsp;<BR><BR><FONT color=#0033cc>14。byte数据类型转换成int型??</FONT><BR>我用byte型读进一组数据想把他转成int型进行运算如何做呢?<BR>如果再把int型转回byte又怎么实现呢?&nbsp;<BR><BR>回复人：　louifox(兰陵笑笑生)　(2001-12-6 9:18:38) 得0分&nbsp;<BR>用下面这些宏：<BR>WORD MAKEWORD(<BR>BYTE bLow,&nbsp;<BR>BYTE bHigh&nbsp;<BR>);<BR>BYTE LOBYTE(<BR>WORD wValue&nbsp;<BR>);<BR>BYTE HIBYTE(<BR>WORD wValue&nbsp;<BR>);<BR><BR>回复人：　chskim(大刀阔斧)　(2001-12-6 9:21:04) 得0分&nbsp;<BR>int i;<BR>BYTE b;<BR>b=128;<BR>i=(int)b;<BR><BR>回复人：　nannet(似的)　(2001-12-6 9:38:24) 得0分&nbsp;<BR>这个宏怎么用呀?有没有简单一点儿的，我现在能把BYTE 转成INT 型了，再转回去直接赋值可以吗？&nbsp;<BR>回复人：　louifox(兰陵笑笑生)　(2001-12-6 9:46:24) 得20分&nbsp;<BR>WORD wa;<BR>BYTE ba=32,bb=64;<BR>wa=MAKEWORD(ba,bb);<BR>...<BR>WORD wa=1234;<BR>BYTE ba,bb;<BR>ba=LOBYTE(wa);<BR>bb=LOBYTE(wa);<BR><BR>回复人：　nannet(似的)　(2001-12-6 9:54:55) 得0分&nbsp;<BR>问题解决了，多谢各位&nbsp;<BR><BR><FONT color=#0033cc>15。类型转换的问题，unsigned int --&gt; lptstr/lpctstr??</FONT><BR>发表时间：2001-8-7 23:49:41<BR>如果强制转换的话，会出现致命错误，有什么好的办法呢？<BR>能列举一些其他的办法吗？<BR>谢谢大虾！&nbsp;<BR><BR>回复人：　AlphaOne(总是第一个倒下)　(2001-8-8 0:02:43) 得5分&nbsp;<BR>你为什么要强行转换呢？<BR>如果你是要把int 的值作为 lptstr/lpctstr 的内容的话，<BR>可以用CString:<BR>unsigned int a = 100;<BR>LPCTSTR lpText;<BR>CString str;<BR>str.Format("%d",a);<BR>lpText = (LPCTSTR)str;<BR><BR>回复人：　tryibest(编の魂)　(2001-8-8 8:20:20) 得5分&nbsp;<BR>wsprintf(str,"%u",ui);&nbsp;<BR>回复人：　zzh()　(2001-8-8 9:04:39) 得5分&nbsp;<BR>这种情况不需要进行强制转换，直接使用wsprintf就可以了。&nbsp;<BR>回复人：　GJA106(中文字符)　(2001-8-8 10:10:51) 得5分&nbsp;<BR>unsigned int m_na=22;<BR>LPTSTR lptstr;<BR>wsprintf(lptstr,"%u",m_na);<BR><BR><FONT color=#0033cc>16。关于COM类型转换问题??<BR></FONT>我定义了两个变量，一个是void *piaRef=new unsigned char[1000];另一个是m_Temp=new CComVariant();我的问题是如何将piaRef中的值<BR>COPY到m_Temp中。&nbsp;<BR><BR>回复人：　nichang()　(2001-11-21 15:34:04) 得0分&nbsp;<BR>CComBSTR bsRef=piaRef;<BR>m_Temp=bsRef.copy()&nbsp;<BR>回复人：　VincentChin(瘟神)　(2001-11-21 17:04:24) 得0分&nbsp;<BR>CComBSTR bsRef=piaRef;<BR>//error C2440: 'initializing' : cannot convert from 'void *' to 'class ATL::CComBSTR'<BR>m_Temp=bsRef.copy();<BR>//error C2440: '=' : cannot convert from 'unsigned short *' to 'class ATL::CComVariant *'&nbsp;<BR>回复人：　nichang()　(2001-11-21 17:14:28) 得0分&nbsp;<BR>将void*改为unsigned char *&nbsp;<BR>回复人：　VincentChin(瘟神)　(2001-11-21 17:22:22) 得0分&nbsp;<BR>我用CComBSTR bsRef=(unsigned char*)piaRef，也不行吗？&nbsp;<BR>回复人：　VincentChin(瘟神)　(2001-11-21 17:28:06) 得0分&nbsp;<BR>会报错：<BR>error C2440: 'type cast' : cannot convert from 'unsigned char *' to 'class ATL::CComBSTR'&nbsp;<BR>回复人：　nichang()　(2001-11-22 9:12:14) 得0分&nbsp;<BR>m_Temp=::SysAllocString((OLECHAR *)piaRef)&nbsp;<BR>回复人：　VincentChin(瘟神)　(2001-11-22 10:43:07) 得0分&nbsp;<BR>//error C2440: '=' : cannot convert from 'unsigned short *' to 'class ATL::CComVariant *'&nbsp;<BR>回复人：　VincentChin(瘟神)　(2001-11-22 11:22:35) 得0分&nbsp;<BR>m_Temp=new CComVariant(::SysAllocString(OLECHAR *)piaRef));没有出错，但是我的m_Temp是COM组件中的一个PROPERTY，我想返回的是<BR>unsigned char类型（单字节），但经过上述转换后，就不再是单字节了呀！怎么办？&nbsp;<BR>回复人：　jiangsheng(蒋晟)　(2001-11-22 11:36:58) 得0分&nbsp;<BR>把这个属性的类型改成BSTR&nbsp;<BR>回复人：　GrayWhite(灰白)　(2001-11-22 12:01:09) 得0分&nbsp;<BR>m_Temp = new CComVariant((char*) piaRef);就可以了。VB就是用的BSTR,你要给谁用阿？VC不用VARIANT的。&nbsp;<BR>回复人：　GrayWhite(灰白)　(2001-11-22 12:18:18) 得19分&nbsp;<BR>哦，我明白了，你要各字节数组：<BR>SAFEARRAY *psa = SafeArrayCreateVector(VT_UI1, 0, 1000);<BR>if (!psa)<BR>_com_issue_error(ERROR_NOT_ENOUGH_MEMORY);<BR><BR>HRESULT hr<BR>for (long i = 0; i &lt; 2; i ++)<BR>{<BR>if (FAILED (hr = SafeArrayPutElement(psa, &amp;i, piaRef + i)))<BR>_com_issue_error(hr);<BR>}<BR><BR>_variant_t va; // include &lt;comdef.h&gt;<BR>va.vt = VT_ARRAY | VT_UI1;<BR>va.parray = psa;<BR><BR>m_Temp = new CComVariant(va);&nbsp;<BR>回复人：　VincentChin(瘟神)　(2001-11-22 14:21:08) 得0分&nbsp;<BR>SafeArrayPutElement(psa, &amp;i, piaRef + i)<BR>//error C2036: 'void *' : unknown size&nbsp;<BR>回复人：　VincentChin(瘟神)　(2001-11-22 14:46:05) 得0分&nbsp;<BR>To GrayWhite:为什么要for(long i=0;i&lt;2;i++)?&nbsp;<BR>回复人：　nichang()　(2001-11-22 15:16:35) 得0分&nbsp;<BR>到底你想怎样转换嘛，是将数组内的值拷贝到CComVariant中存为字符串吗?&nbsp;<BR>回复人：　VincentChin(瘟神)　(2001-11-22 15:28:35) 得0分&nbsp;<BR>我是想把piaRef中的值照原样返回给其它程序使用。我正在做的是一个COM组件。谢谢各位！&nbsp;<BR>回复人：　nichang()　(2001-11-22 15:34:40) 得10分&nbsp;<BR>unsigned char *s=new unsigned char[1000];<BR>strcpy((char*)s,"1234");//可以用你自己方法设置s中的值。<BR>BSTR bstrS;<BR>oleS=A2WBSTR((char*)s);//将char*转换成BSTR类型<BR><BR>CComVariant comVT;<BR>comVT=oleS;//将BSTR转成CComVariant,这里一步也可，comVT=A2WBSTR((char*)s);<BR><BR>回复人：　VincentChin(瘟神)　(2001-11-22 16:54:07) 得0分&nbsp;<BR>谢谢你！<BR>但我还有一个问题，就是如果在s中有'\0'之类的东西我该怎么返回呢？char *遇到'\0'会认为到头了。完整的设计是这样的，我定义一个void * 用来从一个外部设备获取数据，该数据应该是unsigned char，我想把这个返回的数据作为属性传出，让其它应用使用（如VB）。&nbsp;<BR>回复人：　nichang()　(2001-11-22 17:18:09) 得0分&nbsp;<BR>将'\0'转换成其它如'\1'就OK了，&nbsp;<BR>回复人：　jiangsheng(蒋晟)　(2001-11-22 18:07:16) 得0分&nbsp;<BR>用字符串数组&nbsp;<BR>回复人：　VincentChin(瘟神)　(2001-11-23 15:54:39) 得0分&nbsp;<BR>谢谢各位的回复！我的问题解决了！如下：<BR>SAFEARRAY *psa = SafeArrayCreateVector(VT_UI1, 0, 1000);<BR>if (!psa)<BR>return S_FALSE;<BR>HRESULT hr;<BR>for (long i = 0; i &lt; 1000; i ++)<BR>if (FAILED (hr = SafeArrayPutElement(psa, &amp;i, ((unsigned char*)piaRefTemplate) + i)))<BR>return S_FALSE;<BR>VARIANT va;<BR>va.vt = VT_ARRAY | VT_UI1;<BR>va.parray = psa;<BR>CComVariant *m_Temp = new CComVariant();<BR>m_Temp-&gt;Copy(&amp;va);<BR><BR><FONT color=#0033cc>17。类型转换 static_cast reinterprete_cast 的区别??</FONT><BR>static_cast reinterprete_cast 的区别&nbsp;<BR><BR>回复人：　tar(GPS)　(2001-11-21 10:06:41) 得0分&nbsp;<BR>static_cast会检查转换类型健的相关性<BR>如果没有的画会有编译错误<BR>reinterprete_cast就是硬转了&nbsp;<BR>回复人：　tigerwoods(tao)　(2001-11-21 12:28:19) 得0分&nbsp;<BR>是否可以这样理解：在多重继承中，static_cast可实现对象指针的移动，从而指向正确的父类对象部分，而reinterprete_cast不作偏移？&nbsp;<BR>回复人：　liu_feng_fly(我恨死驱动程序了，哎，就是为了混口饭吃)　(2001-11-21 12:35:14) 得0分&nbsp;<BR>在多重继承中可以用dynamic_cast啊&nbsp;<BR><BR><FONT color=#0033cc>18。那如何取得CString中的字符串？？<BR></FONT>回复人：　nichang()　(2001-11-5 17:06:00) 得0分&nbsp;<BR>=(LPCTSTR)CString变量&nbsp;<BR>回复人：　snake1122(领悟)　(2001-11-5 17:12:16) 得0分&nbsp;<BR>方法太多了:<BR>GetAt,Left,Mid,Right等等，就看你怎么取了！&nbsp;<BR>回复人：　dusb(保时捷)　(2001-11-5 17:34:29) 得0分&nbsp;<BR>可是不管是GetAt，Left，Mid，Right返回类型都是CString，还是不能用，我是要取其中的字符串，奇怪的是，VC中没有string类型。（我要的字符串是给树型控件中的分支名称）&nbsp;<BR>回复人：　Alps_lou(云飞扬)　(2001-11-5 17:41:36) 得0分&nbsp;<BR>有string类型的啊，要包含&lt;string&gt;&nbsp;<BR>回复人：　luxes()　(2001-11-5 17:42:19) 得0分&nbsp;<BR>加上(LPCTSTR)，相当于一个const char *了，还不能用？&nbsp;<BR>回复人：　wt007(tt)　(2001-11-5 17:48:33) 得0分&nbsp;<BR>GetBuffer&nbsp;<BR>回复人：　espon99()　(2001-11-5 17:54:06) 得20分&nbsp;<BR>(LPSTR)(LPCTSTR)<BR><BR>回复人：　ineedyou(古寺僧)　(2001-11-5 17:59:29) 得0分&nbsp;<BR>...m_str.GetBuffer(needlen)...;<BR>....<BR>m_str.ReleaseBuffer()&nbsp;<BR>回复人：　dusb(保时捷)　(2001-11-6 15:08:36) 得0分&nbsp;<BR>espon99大侠，果然是绝招，不过能否解释一下啊？&nbsp;<BR><BR><FONT color=#0033cc>19。如何从CString类型转换为Unicode string 类型？</FONT><BR>回复人：　ychener(贫血)　(2001-10-20 10:28:48) 得0分&nbsp;<BR>CString本身就支持Unicode的。 <BR>只要你选择的是UniCode编译，生成的可执行程序就是支持UniCode的&nbsp;<BR><BR>回复人：　ychener(贫血)　(2001-10-20 10:30:04) 得0分&nbsp;<BR>CString类是自适应的就像TCHAR一样，如果你定义了UniCode宏 就会以UniCode编译&nbsp;<BR><BR>回复人：　xjl1980_81(阿龙)　(2001-10-20 10:35:16) 得0分&nbsp;<BR>不是呀，我有个函数中有一个参数需Unicode string 类型的，比如应该填L"abc",而且引号中的内容要有变化，现在我有一个 temp变量，是CString类型的，如何用呀？&nbsp;<BR>回复人：　xt_jat(桑巴)　(2001-10-20 10:39:37) 得0分&nbsp;<BR>_T()<BR>_TEXT()<BR>行不行？&nbsp;<BR>回复人：　xjl1980_81(阿龙)　(2001-10-20 10:43:18) 得0分&nbsp;<BR>不行&nbsp;<BR>回复人：　Jeffery__Chen()　(2001-10-20 11:04:53) 得0分&nbsp;<BR>强制转化：<BR>CString temp;<BR>WCHAR wTemp = (WCHAR)temp;&nbsp;<BR>回复人：　xjl1980_81(阿龙)　(2001-10-20 11:37:06) 得0分&nbsp;<BR>to:Jeffery__Chen()　<BR>不对呀，出现不能转换的错误&nbsp;<BR>回复人：　hongzhh(关儿)　(2001-10-20 11:39:42) 得0分&nbsp;<BR>问题是这样的：<BR>temp 是 CString类型变量，值为zhh<BR>现在有一个API&nbsp;<BR>PCCERT_CONTEXT WINAPI CertFindCertificateInStore(<BR>HCERTSTORE hCertStore,&nbsp;<BR>DWORD dwCertEncodingType,&nbsp;<BR>DWORD dwFindFlags,&nbsp;<BR>DWORD dwFindType,&nbsp;<BR>const void *pvFindPara, //此处用 L"zhh" 没问题&nbsp;<BR>//请问怎么转换 可以 用temp<BR><BR>PCCERT_CONTEXT pPrevCertContext&nbsp;<BR>);<BR><BR>在此谢谢大家，请帮忙看看<BR><BR>回复人：　hongzhh(关儿)　(2001-10-20 13:27:10) 得0分&nbsp;<BR>WCHAR wszDomain[256];&nbsp;<BR>MultiByteToWideChar( CP_ACP, 0, temp,<BR>strlen(temp)+1, wszUserName,&nbsp;<BR>sizeof(wszUserName)/sizeof(wszUserName[0]) );<BR><BR><BR>wszUserName就是转换后的值<BR><BR>回复人：　ychener(贫血)　(2001-10-23 11:43:05) 得0分&nbsp;<BR>只要你用的是CString的函数就行的，如果你要用类似strcpy函数时，看看MSDN中一般情况下都有响应的函数对于Unicode的。只要换成_tcscpy等等。&nbsp;<BR>回复人：　ychener(贫血)　(2001-10-23 11:44:10) 得0分&nbsp;<BR>你有没有定义Unicode宏？&nbsp; <BR><FONT color=#0033cc>20。请问在用ATL且不支持MFC的组件开发中，如何将从数据库中读到的DATE数据类型转换回为字符串??&nbsp;<BR></FONT><BR>复人：　zhxuys(zhxuys)　(2001-9-24 10:36:47) 得0分&nbsp;<BR>ATL把datetime类型的列映射为DBTIMESTAMP类型，可取出该类型的year、month、day等，然后将这些数据传递回客户端，在客户端用CTime来构造&nbsp;<BR>回复人：　YUANXU(旭)　(2001-9-24 11:18:14) 得0分&nbsp;<BR>to zhxuys:CTime是MFC类，在ATL 不支持MFC时不能用。DATE其实质是个double*&nbsp;<BR>回复人：　zhxuys(zhxuys)　(2001-9-24 11:57:01) 得0分&nbsp;<BR>你在客户端与服务器端只用ATL规定的数据类型或VARIANT类型，而在客户端，可以用MFC来重新构造想要的数据结构&nbsp;<BR><BR><FONT color=#0033cc>21。类型转换，CString to wchar_t&nbsp;??</FONT><BR><BR>CString ss("aabb");<BR>wchar_t* cc;<BR>cc=ss.AllocSysString();<BR><BR><FONT color=#0033cc>22。如何将CString类型转换为_bstr_t类型？</FONT><BR>回复人：　wei97081116(韦小宝)　(2001-9-4 11:19:30) 得20分&nbsp;<BR>CString b;<BR>_bstr_t a;<BR>a=(_bstr_t)b;&nbsp;<BR><BR>回复人：　zhaozhen1212(赵振)　(2001-9-18 1:30:18) 得0分&nbsp;<BR>_bstr_t a=b.AllocSysString();;<BR><BR><FONT color=#0033cc>23。如何把一个CString类型转换成一个普通的字符串，如char*?<BR></FONT><BR>回复人：　liu_feng_fly(我恨死驱动程序了，哎，就是为了混口饭吃)　(2001-9-17 18:00:52) 得0分&nbsp;<BR>所以，直接用就可以，因为类里边有这样的转换函数&nbsp;<BR>回复人：　ydogg(灰毛兔频频)　(2001-9-17 18:01:21) 得0分&nbsp;<BR>CString show;<BR><BR>char *p = show.GetBuffer(show.GetLength());&nbsp;<BR>回复人：　jiangping_zhu(娜可露露之风之刃)　(2001-9-17 18:02:05) 得0分&nbsp;<BR>(char*)(LPCTSTR)str&nbsp;<BR>回复人：　bmouse(老鼠)　(2001-9-18 0:10:56) 得0分&nbsp;<BR>同意楼上!&nbsp;<BR>回复人：　bmouse(老鼠)　(2001-9-18 0:13:22) 得0分&nbsp;<BR>你还可以通过GetBuff来直接操作CString的缓冲区,不过要记着释放缓冲区.&nbsp;<BR><BR><FONT color=#0033cc>24。CString 类型转换成 unsigned char类型吗？？</FONT><BR>回复人：　LJN(*)风流倜傥无人及，玉树偏又临风立(*)　(2001-9-17 12:46:01) 得0分&nbsp;<BR>可以用CString.GetBuffer函数&nbsp;<BR>回复人：　xpmao()　(2001-9-17 13:09:09) 得0分&nbsp;<BR>CString strWork;<BR>MessageBox(0,(LPSTR)strWork,0,0);<BR>或MessageBox(0,strWork.GetBuffer(0),0,0);<BR><BR>回复人：　sandd(降龙掌)　(2001-9-17 13:17:32) 得0分&nbsp;<BR>CString string;<BR><BR>(LPCTSTR)string;&nbsp;<BR>回复人：　jeff_hunter(PandaLee)　(2001-9-17 13:45:30) 得0分&nbsp;<BR>(unsigned char *)(LPCTSTR)&nbsp;<BR>回复人：　fandh(好了)　(2001-9-17 14:00:57) 得0分&nbsp;<BR>用(unsigned char *)(LPCTSTR)即可&nbsp; <BR>回复人：　ygd(ygd)　(2001-9-17 16:11:17) 得0分&nbsp;<BR>unsigned char *p;<BR>CString str;<BR>int length=str.GetLength();<BR>for(int i=0;i&lt;length;i++)<BR>p[i]=str.GetAt(i);&nbsp;<BR>回复人：　swordbroken(断剑书生)　(2001-9-17 16:25:57) 得0分&nbsp;<BR>CString str;<BR>unsigned char string[30];<BR>strcpy(string,str);&nbsp;<BR><BR><FONT color=#0033cc>25。何将一个unsigned int 类型变量值赋给类型为unsigned short的变量，并保证数值不丢失（当然数值在一定范围内)？</FONT><BR>回复人：　maxsuy(魔法师兔子)　(2001-8-14 16:37:30) 得0分&nbsp;<BR>直接=就OK了&nbsp;<BR>回复人：　oppmm(ppmm)　(2001-8-14 16:38:11) 得0分&nbsp;<BR>直接赋值&nbsp;<BR>回复人：　milefo(弥勒佛)　(2001-8-14 16:40:40) 得0分&nbsp;<BR>如果数值在一定范围内怎么回丢失呢？<BR>unsigned short a;<BR>unsigned int b;<BR>a=( b &amp; 0xffff);<BR>你试试看吧！<BR><BR><FONT color=#0033cc>26。CString ----char*&nbsp;</FONT><BR>定义了char* aa的变量，现在有一个CString的变量bb，怎样把bb的值赋给aa呢?&nbsp;<BR><BR>回复人：　emmai(WaTaXiWaWaTaXi)　(2001-8-10 11:57:33) 得0分&nbsp;<BR>aa=bb.GetBuffer();&nbsp;<BR>回复人：　hswqs(??????????????????)　(2001-8-10 11:59:01) 得0分&nbsp;<BR>aa= (LPSTR)(LPCTSTR)bb;&nbsp;<BR>回复人：　ydogg(灰毛兔)　(2001-8-10 12:27:23) 得0分&nbsp;<BR>1.aa=bb.GetBuffer(bb.GetLenth());//第一种方法<BR>2.aa= (LPSTR)(LPCTSTR)bb; //第二种方法&nbsp;<BR>回复人：　zhizhi()　(2001-8-10 13:16:23) 得0分&nbsp;<BR>aa= (char *)(LPCTSTR)bb,hehe&nbsp;<BR><BR><FONT color=#0033cc>27。在一个COM的接口函数中有一个 BSTR* 类型的参数，需要把一个 char * 类型转换为 BSTR* 类型，不知道如何转换？ 由于调用这个函数后需要把这个参数值再取出来所以只能用指针，另外在调用的时候应该用什么类型的数据传递参数呢？大虾帮忙。<BR></FONT><BR>BSTR bstr = SysAllocString(L"字符串");<BR>这样转换,用的时候你用地址操作符&amp;啊，要不指针还得new&nbsp;<BR><BR>回复人：　yongyue2000i(小吕)　(2001-9-9 18:38:26) 得13分&nbsp;<BR>CString str = "abcd";<BR>BSTR bstr = str.AllocSysString();&nbsp;<BR>回复人：　houjzs()　(2001-9-9 19:14:44) 得13分&nbsp;<BR>BSTR b = SysAllocString(OLESTR("your string"));<BR><BR><FONT color=#0033cc>28。要把一个double的数字输出到CEdit控件是否需要类型转换？</FONT><BR>回复人：　jiangsheng(蒋晟)　(2001-8-24 14:46:17) 得0分&nbsp;<BR>void AFXAPI DDX_Text( CDataExchange* pDX, int nIDC, double&amp; value );&nbsp;<BR>回复人：　xiezhsh(雪中行)　(2001-8-24 14:56:22) 得0分&nbsp;<BR>假如你的ＣＥｄｉｔ相关的成员变量是Ｄｏｕｂｌｅ型的，那根本用不着．（ＣｌａｓｓＷｉｚａｒｄ增加成员变量的对话框中，Variable Type选择Double可）&nbsp;<BR>回复人：　xiezhsh(雪中行)　(2001-8-24 14:58:16) 得0分&nbsp;<BR>假如你的ＣＥｄｉｔ相关的成员变量不是Ｄｏｕｂｌｅ型的，是ＣＳｔｒｉｎｇ型，那就需要用ltoa()来转换成ＣＳｔｒｉｎｇ型，&nbsp;<BR>回复人：　haven(大天)　(2001-8-24 14:58:32) 得0分&nbsp;<BR>m_Edit.Fromat("%l",VarBouble);<BR>updatedata(false);&nbsp;<BR>回复人：　12345678()　(2001-8-24 14:59:54) 得0分&nbsp;<BR>CString m_Edit.Format("%lf", doubleVar);&nbsp;<BR>GetDlgItem(EditID)-&gt;SetWindowText(m_strEdit);&nbsp;<BR><BR><FONT color=#0033cc>29。该如何把 WINDOWPLACEMENT * 转换成 char **类型??</FONT><BR><BR>(char**)&amp;pWP&nbsp;<BR><BR><FONT color=#0033cc>30。怎样把CString的类型转换成char*型的？</FONT><BR>回复人：　dcz(dcz)　(2001-8-19 19:13:27) 得5分&nbsp;<BR>// str is CString var<BR>char* temp = strdup(str);<BR>...<BR>free(temp);&nbsp;<BR>回复人：　yu900(疾风之狼)　(2001-8-19 19:57:25) 得0分&nbsp;<BR>getbuffer()；即可！&nbsp;<BR>回复人：　aileen_long(挑战2001)　(2001-8-19 21:10:35) 得0分&nbsp;<BR>同意楼上的意见！&nbsp;<BR>回复人：　czh912()　(2001-8-19 21:27:08) 得0分&nbsp;<BR>char buf[20];<BR>printf(buf,"%s",string);<BR><BR>回复人：　casl(casl)　(2001-8-19 22:59:44) 得5分&nbsp;<BR>CString s("abc");<BR>char* temp=s.GetBuffer(10);<BR>...<BR>s.ReleaseBuffer();&nbsp;<BR>回复人：　cocia(高亚)　(2001-8-19 23:04:23) 得0分&nbsp;<BR>char* temp=s.GetBuffer(10);<BR>10是什么意思啊<BR><BR>回复人：　kevin_dong(梦仙人)　(2001-8-20 10:26:35) 得0分&nbsp;<BR>// str is CString var<BR>char* temp = strdup(str);<BR>// free<BR>free(temp);&nbsp;<BR>我的这段代码在一个程序中能通过编译，但是在另外一个中总是出现cannot convert parameter 1 from 'class CString' to 'const char *'的错误。str和temp的类型都一样。这是为什么？<BR><BR>回复人：　dcz(dcz)　(2001-8-20 14:13:45) 得0分&nbsp;<BR>you may setting your compiler option to UNICODE, in this case, declare the var:<BR><BR>// str is CString var<BR>_TCHAR* temp = _tcsdup(str);<BR><BR>// free<BR>free(str);<BR><BR><FONT color=#0033cc>31。SA,SB为两个结构类型??</FONT><BR>SA* A;<BR>SB* B;<BR>(SB*)A-&gt;...（调用函数）<BR>请问此时A的类型，是指向SA还是SB<BR>此时编译器是生成一个临时指针吗？<BR>另外，<BR>B=(SB*)A;此时A又是什么类型？？？<BR><BR>回复贴子：&nbsp;<BR>回复人：　ddeng(登登)　(2001-8-9 17:13:58) 得0分&nbsp;<BR>A的类型始终是SA *<BR>B的类型始终是SB *<BR>当进行强制类型转换时使的是临时指针&nbsp;<BR>回复人：　gold_water(风雨无阻)　(2001-8-9 17:30:46) 得0分&nbsp;<BR>同意楼上的。&nbsp;<BR><BR><FONT color=#0033cc>32。char buff[100],char UserName[50][100],怎么将buff的值传给UserName，是其成为UserName数组中的某一项呢？？<BR></FONT><BR>//0=&lt;i&lt;50<BR>strcpy(UserName[i],buff);&nbsp;<BR>回复人：　Ashura(阿修罗)　(2001-7-26 10:08:20) 得0分&nbsp;<BR>呵呵，benbensan抢先一步。&nbsp;<BR>回复人：　tuita(斗牛士)　(2001-7-26 10:13:22) 得0分&nbsp;<BR>for (i=0;i&lt;100;i++)<BR>*(*(username+x)+i)=*(buffer+i)<BR>其中0《X〈50<BR>benbensan写的也对<BR><BR>回复人：　kekeke(我是来向大家学习的)　(2001-7-26 10:24:22) 得0分&nbsp;<BR>那反过来呢？把UserName中的某一项读出赋值给buff呢？怎么弄？&nbsp;<BR>回复人：　benbensan(笨笨三)　(2001-7-26 10:26:53) 得0分&nbsp;<BR>//0=&lt;i&lt;50<BR>strcpy(UserName[i],buff);&nbsp;<BR>回复人：　benbensan(笨笨三)　(2001-7-26 10:28:15) 得0分&nbsp;<BR>对不起，能错了，不过建议你看一下C语言了的指针和数组<BR>//0=&lt;i&lt;50<BR>strcpy(buff,UserName[i]);&nbsp;<BR><BR>回复人：　jfzsl(剿匪总司令)　(2001-7-26 10:32:57) 得0分&nbsp;<BR>好好看看老潭的书先！OK？&nbsp;<BR>回复人：　kekeke(我是来向大家学习的)　(2001-7-26 10:44:25) 得0分&nbsp;<BR>好。。。。！&nbsp;<BR><BR><FONT color=#0033cc>33。请问怎样把SYSTEMTIME类型转换成time_t类型?</FONT><BR>SYSTEMTIME st;<BR>GetLocalTime(&amp;st);<BR>CTime tm(st.wYear,st.wMonth,st.wDay,st.wHour,st.wMinute,st.wSecond);<BR>time_t t = tm.GetTime();<BR><BR><FONT color=#0033cc>34。unsigned char Exponent[10]; //e<BR>unsigned long eBytes; //e的字节数<BR>如何转换成DWord型!&nbsp;??</FONT><BR><BR>用强制类型转换呀<BR>(DWord)eBeytes;<BR>(DWord)Exponent[i];//(0&lt;=i&lt;=10);<BR><BR>回复人：　xjl1980_81(阿龙)　(2001-7-26 16:47:29) 得0分&nbsp;<BR>我是说把e转换成DWORD型<BR>也就是说把Exponent中的内容转换成DWORD型<BR><BR>回复人：　cloudshadow1(云影)　(2001-7-26 17:13:30) 得0分&nbsp;<BR>用强制类型转换就可以了，（DWORD的高24位自动加0）<BR>DWORD Des[10]<BR>for (int i=0;i&lt;11;i++)<BR>Des[i]=Exponent[i];<BR>至于那个ULONG的也是用强制类型软换就可以了<BR><BR><FONT color=#0033cc>35。请问怎样把time_t类型转换成SYSTEMTIME类型？</FONT><BR>回复人：　haven(大天)　(2001-7-26 17:12:36) 得0分&nbsp;<BR>typedef struct _SYSTEMTIME<BR>typedef long time_t<BR>很明显不行嘛！&nbsp;<BR>回复人：　facexy(FACE仔)　(2001-7-26 17:17:38) 得0分&nbsp;<BR>哎呀，问错了，前后对象相反了；-（<BR>忙昏了的结果…………<BR><BR>另外，TO 楼上的：<BR>转换是可以的<BR>struct tm *tblock;<BR>SYSTEMTIME SystemTime;<BR>memset(&amp;SystemTime,0,sizeof(SYSTEMTIME));<BR>tblock=localtime(&amp;timer);<BR>SystemTime.wYear=tblock-&gt;tm_year+1900;<BR>SystemTime.wMonth=tblock-&gt;tm_mon+1;<BR>SystemTime.wDay=tblock-&gt;tm_mday;<BR>SystemTime.wHour=tblock-&gt;tm_hour;<BR>SystemTime.wMinute=tblock-&gt;tm_min;<BR>SystemTime.wSecond=tblock-&gt;tm_sec;<BR>SystemTime.wDayOfWeek=tblock-&gt;tm_wday;<BR>return &amp;SystemTime;&nbsp;<BR>回复人：　zjh73(大章鱼)　(2001-7-26 20:28:28) 得0分&nbsp;<BR>有两种方法：<BR>1、用CTime类<BR>先用time_t类型构造一个CTime对象，再定义一个SYSTEMTIME结构，最后用CTime类的成员函数GetAsSystemTime将时间转换到SYSTEMTIME结构中<BR>即可。<BR>2、用gmtime函数<BR>gmtime函数将time_t时间转换到tm结构中并返回一个tm指针，再将tm结构的相对应的项赋给SYSTEMTIME相对应的项即可，不过用这种方法要注<BR>意这两种结构在天、星期等方面的记数方法有点区别，一个一般从0开始，一个一般从1开始，赋值时要注意校正，还有要注意的是SYSTEMTIME<BR>结构中有一项是毫秒，而time_t是以秒记数的。&nbsp;<BR>回复人：　zjh73(大章鱼)　(2001-7-26 20:32:13) 得0分&nbsp;<BR>反过来也可以用Ctime类的方法<BR>就是先用SYSTEMTIME结构构造一个CTime对象，在用CTime类中的成员函数GetTime返回一个对应的time_t即可。 36。我现在正在学习SDK编程，遇到的问题是：<BR>我定义了一个静态长整形变量，<BR>static long lScore=0;<BR>我想把窗口的标题换成长整形数值,用SetWindowText函数来实现，<BR>由于它的第二个参数要求数据类型为 unsigned short *,但用其来实现强制转换时<BR>总是出现编译错误：<BR>cannot convert parameter 2 from 'unsigned short *' to 'const char *'<BR>后来改成来LPCTSTR 来实现强制转换，没有出现编译错误，但函数总是执行不成功,<BR>请教各位高人，这倒底是怎么回事？？？<BR><BR>回复贴子：&nbsp;<BR>回复人：　prog_st(st)　(2001-8-4 21:20:07) 得0分&nbsp;<BR>/* ITOA.C: This program converts integers of various<BR>* sizes to strings in various radixes.<BR>*/<BR><BR>#include &lt;stdlib.h&gt;<BR>#include &lt;stdio.h&gt;<BR><BR>void main( void )<BR>{<BR>char buffer[20];<BR>int i = 3445;<BR>long l = -344115L;<BR>unsigned long ul = 1234567890UL;<BR><BR>_itoa( i, buffer, 10 );<BR>printf( "String of integer %d (radix 10): %s\n", i, buffer );<BR>_itoa( i, buffer, 16 );<BR>printf( "String of integer %d (radix 16): 0x%s\n", i, buffer );<BR>_itoa( i, buffer, 2 );<BR>printf( "String of integer %d (radix 2): %s\n", i, buffer );<BR><BR>_ltoa( l, buffer, 16 );<BR>printf( "String of long int %ld (radix 16): 0x%s\n", l,&nbsp;<BR>buffer );<BR><BR>_ultoa( ul, buffer, 16 );<BR>printf( "String of unsigned long %lu (radix 16): 0x%s\n", ul,<BR>buffer );<BR>}<BR><BR><BR>Output<BR><BR>String of integer 3445 (radix 10): 3445<BR>String of integer 3445 (radix 16): 0xd75<BR>String of integer 3445 (radix 2): 110101110101<BR>String of long int -344115 (radix 16): 0xfffabfcd<BR>String of unsigned long 1234567890 (radix 16): 0x499602d2<BR><BR><BR>回复人：　lwg7603(刑满释放人员)　(2001-8-4 21:36:15) 得0分&nbsp;<BR>TCHAR str[255]={_T('\0')};<BR>_stprintf(str,_T("%d"),lScore);<BR>SetWindowText(hwnd,str);<BR><BR>37。我用socket发送的的buf中间需要的是 char *类型的数据，我想将一个 struct 直接转换成 char * 发过去。<BR>我用<BR>struct ABCD *abcd;<BR>char *buf;<BR>abcd = (ABCD *)calloc(1,sizeof(ABCD));<BR>buf = (char *)calloc(1,sizeof(ABCD));<BR>///<BR>给abcd 中间赋值，其中有多个char[]的值和int 的值<BR>///<BR>memcpy(buf,abcd,sizeof(ABCD));<BR>//strcpy(buf,(char *)abcd)；也不可以<BR>sock(host,buf,....);<BR>//sock(host,(char *)buf,...);也不可以<BR>问题就是在这里，这个buf中间的值总是不对，大家知道为什么否。<BR><BR>回复人：　wolf721()　(2001-7-30 18:18:34) 得5分&nbsp;<BR>你传的是个指针值，而不是数据&nbsp;<BR>回复人：　kiko_lee(到处瞧瞧)　(2001-7-30 18:50:49) 得0分&nbsp;<BR>但是用memcpy这个是将整个数据都复制过去&nbsp;<BR>回复人：　lz_0618(lz_0618)　(2001-7-30 19:26:44) 得5分&nbsp;<BR>你用的VC???改成ABCD *abcd;后编译一点问题也没有啊！<BR>sock(host,buf,....);这不知是什么，自定义函数？<BR><BR>typedef struct _ABCD<BR>{<BR>int ID;<BR>char Name[10];<BR>}ABCD;<BR><BR>.......<BR><BR><BR>ABCD *abcd;<BR>char *buf;<BR>abcd = (ABCD *)calloc(2,sizeof(ABCD));<BR>buf = (char *)calloc(2,sizeof(ABCD));<BR>///<BR>//给abcd 中间赋值，其中有多个char[]的值和int 的值<BR>abcd[0].ID =1;<BR>abcd[1].ID =2;<BR>///<BR>memcpy(buf,abcd,2*sizeof(ABCD));<BR>strcpy(buf,(char *)abcd);//也不可以<BR><BR>buf中的内容也正确！！<BR><BR>回复人：　kiko_lee(到处瞧瞧)　(2001-7-31 8:57:52) 得0分&nbsp;<BR>我按照楼上的兄弟说的，做了一下，但是仍然做不下来，我用<BR>memcpy(buf,abcd,sizeof(ABCD));<BR>中间的abcd，不知道是不是地址的问题。&nbsp;<BR>回复人：　supersusheng(小苏)　(2001-7-31 14:30:42) 得0分&nbsp;<BR>老大，你sizeof()得出的数值事多大，看看吧。&nbsp;<BR>回复人：　ydogg(灰毛兔)　(2001-7-31 14:41:52) 得0分&nbsp;<BR>只能传递流数据，结构是传递不过去的。&nbsp;<BR>回复人：　IamNotMan(NorGirl)　(2001-7-31 14:50:53) 得5分&nbsp;<BR>我常这么用<BR>ABCD a ;<BR>//给a的各个域赋值（一定不能含有指针项）<BR>char* buff = new char[sizeof(ABCD)];<BR>memcpy(buff,&amp;a,sizeof(ABCD));<BR>//或者 *（ABCD*)buff = a;<BR>.................<BR>如果buff里的数对，说明问题不在这儿吧<BR><BR>回复人：　zb_china(最后一座水车zb_china新浪)　(2001-7-31 15:16:24) 得0分&nbsp;<BR>看不明白&nbsp;<BR>回复人：　eggplant(拉拉)　(2001-7-31 15:42:48) 得0分&nbsp;<BR>最好使用memcpy(),因为struct中的值有可能包含零字节，所以strcpy（）可能不对，如果传递struct,最好把struct的字节对齐改为以字节为单位。&nbsp;<BR>回复人：　lvfengxun(lfx)　(2001-7-31 16:06:57) 得5分&nbsp;<BR>直接将结构指针作为send的参数发就可以了,还用转换什么<BR>有必要在这里讨论吗?<BR>struct AA<BR>{<BR>int a;<BR>char b[100];<BR>};<BR>struct AA aa;<BR>aa.a=11;<BR>strcpy(aa.b,"aaa");<BR>send(hSocket,(char *)(&amp;aa),sizeof(aa),0);<BR>//OK&nbsp;<BR>回复人：　mydewang(mydewang)　(2001-7-31 16:33:21) 得0分&nbsp;<BR>其实这里是一个字节对齐的问题,<BR>比如<BR>struct AA<BR>{<BR>int a;<BR>char b;<BR>};<BR>那么sizeof( struct AA )就不等于5了,而是8了,所以,将这个结构赋值给一个char *,里面会多出一些零...<BR><BR>需要解决这个问题,可以在Project-&gt;Setting-&gt;Link-&gt;Project Options里加上/Zp1<BR><BR>另外,可以参考一下MSDN里/Zp的编译选项.....&nbsp;<BR>回复人：　lz_0618(lz_0618)　(2001-7-31 19:43:54) 得0分&nbsp;<BR>根本不是什么字节对齐的问题，我上面的程序经过测试都好用啊，这位老兄用我的那段程序究竟是什么错误，能说清楚点吗？？？<BR><BR>我这边用socket发送结构是一点问题也没有啊，而且是在VC和Delphi编的程序间通讯，当然，这时应该注意字节对齐的问题了，在VC程序间，<BR>只要不是故意将服务器和客户端的编译环境设的不一样，肯定是没有什么问题的，最多是多传几个Bit罢了。&nbsp;<BR>回复人：　kiko_lee(到处瞧瞧)　(2001-8-3 11:02:51) 得0分&nbsp;<BR>我发现将char * memcpy 到 char * 中间都有点问题，但是如果放到 char []中间就可以了，大家知道为什么否？&nbsp;<BR>回复人：　ydogg(灰毛兔)　(2001-8-3 11:40:35) 得0分&nbsp;<BR>memcpy不copy最后的'\0'...&nbsp;<BR>回复人：　wenjunlin2000(微软克星)　(2001-8-3 14:32:17) 得0分&nbsp;<BR>是你看错了<BR>因为char*是以0 结尾的<BR><BR>回复人：　mc_music(狂沙)　(2001-8-3 15:07:21) 得0分&nbsp;<BR>请注意我的程序:<BR>struct ABCD *abcd;<BR>char *buf;<BR>abcd = (ABCD *)calloc(1,sizeof(ABCD));<BR>//初始化abcd<BR>buf=abcd;//指针直接符值就可以了&nbsp;<BR>回复人：　zhangnanonnet(WinSockZhang)　(2001-8-3 16:21:03) 得0分&nbsp;<BR>你试试把类型变为BYTE&nbsp;<BR>回复人：　kiko_lee(到处瞧瞧)　(2001-8-7 9:21:08) 得0分&nbsp;<BR>不管了，给分，大家都有不少的建议呢。&nbsp;<BR><BR><BR><FONT color=#0033cc>38。double dou=12.34;我如何可以得到char * ch="12.34";转换函数是什么？</FONT><BR><BR>回复人：　wyzegg(蛋)　(2001-7-24 21:26:04) 得50分&nbsp;<BR>double dou=12.34;<BR>char * ch;<BR>ch=malloc(100);<BR>sprintf(ch,"%5.2f",dou);&nbsp;<BR>回复人：　wyzegg(蛋)　(2001-7-24 21:28:24) 得0分&nbsp;<BR>或者<BR>#include &lt;stdlib.h&gt;<BR>#include &lt;stdio.h&gt;<BR><BR>void main( void )<BR>{<BR>int decimal, sign;<BR>char *buffer;<BR>int precision = 10;<BR>double source = 3.1415926535;<BR><BR>buffer = _ecvt( source, precision, &amp;decimal, &amp;sign );<BR>printf( "source: %2.10f buffer: '%s' decimal: %d sign: %d\n",<BR>source, buffer, decimal, sign );<BR>}<BR><BR>但是第一种常用&nbsp;<BR>回复人：　Matrix_w(学会一点点)　(2001-7-24 21:32:43) 得30分&nbsp;<BR>int decimal, sign;<BR>double dou =12.34;<BR>char* ch;<BR>ch = _ecvt(dou,4,&amp;decimal,&amp;sign);<BR><BR>回复人：　imhua(华弟)　(2001-7-24 21:35:02) 得20分&nbsp;<BR>double dou=12.34;<BR>char *str;<BR>gcvt(dou,5,str); //5是长度<BR>MessageBox(str);&nbsp;<BR>回复人：　Matrix_w(学会一点点)　(2001-7-24 21:37:58) 得0分&nbsp;<BR>/* _GCVT.C: This program converts -3.1415e5<BR>* to its string representation.<BR>*/<BR><BR>#include &lt;stdlib.h&gt;<BR>#include &lt;stdio.h&gt;<BR><BR>void main( void )<BR>{<BR>char buffer[50];<BR>double source = -3.1415e5;<BR>_gcvt( source, 7, buffer );<BR>printf( "source: %f buffer: '%s'\n", source, buffer );<BR>_gcvt( source, 7, buffer );<BR>printf( "source: %e buffer: '%s'\n", source, buffer );<BR>}<BR><BR><BR>Output<BR><BR>source: -314150.000000 buffer: '-314150.'<BR>source: -3.141500e+005 buffer: '-314150.'<BR><BR><FONT color=#0033cc>39。 我在ADO中调用一个存储过程，存储过程有三个输入参数@useradd char(30),@username char(10),@userage char(3)，现在要把char&nbsp;<BR>*addr,char *name,char *age分别赋值给他们。??<BR></FONT>我做了如下定义：<BR>_ParameterPtr para1;<BR>_variant_t var1,var2,var3；<BR>==============================================================<BR>var1.vt=VT_BSTR;<BR>var1.bstrval=addr;/////(编译错误）<BR>==============================================================<BR>para1=m_pCommand-&gt;CreateParameter(L"useradd",adBSTR,adParamInput,30,var1);<BR>m_pCommand-&gt;Parameters-&gt;Append(para1);<BR>编译]]></description>
</item><item>
<title><![CDATA[[转载]VC++ ADO开发实践之七]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=fishyqd&amp;id=13051</link>
<author>fishyqd</author>
<pubDate>2006/3/30 21:44:52</pubDate>
<description><![CDATA[
<TABLE style="TABLE-LAYOUT: fixed; BORDER-COLLAPSE: collapse" cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD width="100%" height=38>
<P align=center><B>作者</B>：未知 <B>来源</B>：月光软件站<!--未知--> <B>加入时间</B>：2005-2-28　月光软件站</P></TD></TR>
<TR>
<TD vAlign=top width="100%"><FONT size=2>一致的数据访问技术ADO/OLE DB<BR><BR>&nbsp;&nbsp;&nbsp; Microsoft新近推出的UDA(Universal Data Access,一致数据访<BR>问技术)为关系型或非关系型数据访问提供了一致的访问接口,为企业<BR>级Intranet应用多层软件结构提供了数据接口标准。一致数据访问包<BR>括两层软件接口,分别为ADO(Active Data Object)和OLED B,对应于<BR>不同层次的应用开发,ADO提供了高层软件接口,可在各种脚本语言(Sc<BR>ript)或一些宏语言中直接使用;OLE DB提供了底层软件接口,可在C/C<BR>++语言中直接使用。ADO以OL E DB为基础,它对OLE DB进行了封装。<BR>一致数据访问技术建立在Microsoft的COM(组件对象模型)基础上,它<BR>包括一组COM组件程序,组件与组件之间或者组件与客户程序之间通过<BR>标准的COM接口进行通讯。<BR>&nbsp;&nbsp;&nbsp; 由于ADO建立在自动化(Automation)基础上,所以ADO的应用场合<BR>非常广泛,不仅可在Visual Basic这样的高级语言开发环境中使用,还<BR>可以在一些脚本语言中使用,这对于开发Web应用,在ASP(Active Serv<BR>er Page)的脚本代码访问数据库中提供了操作应用的捷径。本文将首<BR>先介绍ADO和OLE DB的结构模型,以便读者了解ADO与OLE DB之间的关<BR>系,然后介绍ADO的对象模型和ADO的一些特性,同时我们也将通过一些<BR>例子代码向读者展示ADO的用法。<BR>&nbsp;&nbsp;&nbsp; 一、一致数据访问介绍<BR>&nbsp;&nbsp;&nbsp; 随着网络技术和数据库技术的不断发展,现在的应用系统对数据<BR>集成的要求越来越高,这些数据有可能分布在不同的地方,并且使用不<BR>同的格式,例如关系型数据库和操作系统中的文件、电子表格、电子<BR>邮件、多媒体数据以及目录服务信息等等。传统的解决方案是使用大<BR>型的数据库系统,把所有这些数据都移到数据库系统中,然后按照操作<BR>数据库的办法对这些数据进行访问,这样做虽然能够按统一的方式对<BR>数据进行各种操作,但这种间接访问方式带来了很多问题,比如数据更<BR>新不及时、空间资源的冗余和访问效率低等等。<BR>&nbsp;&nbsp;&nbsp; Microsoft公司推出的一致数据访问技术则较好地解决了这些问<BR>题,它使得应用通过一致的接口来访问各种各样的数据,而不管数据驻<BR>留在何处,也不需要进行数据转移或复制、转换,在实现分布式的同时<BR>也带来了高效率。并且UDA技术在统一数据访问接口的同时,它的多层<BR>结构使数据使用方有了更多的选择机会,而它强大的扩展能力也给数<BR>据提供方留下了更多的扩展余地,这种开放型的软件结构使它具有极<BR>强的生命力,所以,这种技术从一推出便获得了广泛的欢迎,可以说,UD<BR>A技术是继ODBC之后的又一数据访问技术的飞跃。<BR>&nbsp;&nbsp;&nbsp; UDA技术包括OLE DB和ADO两层标准接口,OLE DB是系统级的编程<BR>接口,它定义了一组COM接口,这组接口封装了各种数据系统的访问操<BR>作,这组接口为数据使用方和数据提供方建立了标准,OLE DB还提供了<BR>一组标准的服务组件,用于提供查询、缓存、数据更新、事务处理等<BR>操作,因此,数据提供方只需实现一些简单的数据操作,在使用方就可<BR>以获得全部的数据控制能力。<BR>&nbsp;&nbsp;&nbsp; ADO是应用层的编程接口,它通过OLE DB提供的COM接口访问数据,<BR>它适合于各种客户机/服务器应用系统和基于Web的应用,尤其在一些<BR>脚本语言中访问数据库操作是ADO的主要优势。ADO是一套用自动化技<BR>术建立起来的对象层次结构,它比其他的一些对象模型如DAO(Data Ac<BR>cess Object)、RDO(Remote Data Object)等具有更好的灵活性,使用<BR>更为方便,并且访问数据的效率更高。<BR>&nbsp;&nbsp;&nbsp; 图1显示了统一数据访问的软件层次模型。<BR>图1 UDA的层次结构图<BR>&nbsp;&nbsp;&nbsp; 从图中我们可以看出,应用程序既可以通过ADO访问数据也可以直<BR>接通过OLE DB访问数据,而ADO则通过OLE DB访问底层数据。而且,OLE<BR>&nbsp;DB分成两部分,一部分由数据提供者实现,包括一些基本功能,如获取<BR>数据、修改数据、添加数据项等;另一部分由系统提供, 包括一些高<BR>级服务,如游标功能、分布式查询等等。这样的层次结构既为数据使<BR>用者即应用程序提供了多种选择方案,又为数据提供方简化了服务功<BR>能的实现手段,它只需按OLED B规范编写一个COM组件程序即可,使得<BR>第三方发布数据更为简便,而在应用程序方可以得到全面的功能服务,<BR>这充分体现了OLE DB两层结构的优势。<BR>&nbsp;&nbsp;&nbsp; 由于OLE DB和ADO都以COM组件的形式实现,所以COM组件的各种特<BR>性也使得构建数据应用更为灵活,而不仅仅局限于一般的客户机/服务<BR>器或Web应用模型,它既适合于以数据为中心的应用,也适合于多层结<BR>构的分布式软件系统。通过对COM组件的配置,我们可以建立各种复杂<BR>的应用系统。利用从COM到DCOM的位置透明技术,我们可以很方便地建<BR>立分布式应用系统;利用MTS(Microsoft Transaction Server)运行环<BR>境,我们也可以在数据访问一层增加安全性控制,并利用MTS的对象管<BR>理使数据访问效率更高。所有这些功能都无需数据提供方编写代码实<BR>现,只需在DCOM或MTS环境中进行常规的配置即可。<BR>&nbsp;&nbsp;&nbsp; 可以说一致的数据访问技术的核心是OLE DB,OLE DB建立了数据<BR>访问的标准接口,它把所有的数据源经过抽象形成行集(rowset)的概<BR>念。OLE DB模型主要包括以下一些COM对象:<BR>&nbsp;&nbsp;&nbsp; (1)数据源(Data Source)对象 数据源对象对应于一个数据提供<BR>者,它负责管理用户权限、建立与数据源的连接等初始操作。<BR>&nbsp;&nbsp;&nbsp; (2)会话(Session)对象 在数据源连接的基础上建立会话对象,会<BR>话对象提供了事务控制机制。<BR>&nbsp;&nbsp;&nbsp; (3)命令(Command)对象 数据使用者利用命令对象执行各种数据<BR>操作,如查询命令、修改命令等。<BR>&nbsp;&nbsp;&nbsp; (4)行集(Rowset)对象 提供了数据的抽象表示,它可以是命令执<BR>行的结果,也可以直接由会话对象产生,它是应用程序主要的操作对象<BR>。<BR>&nbsp;&nbsp;&nbsp; OLE DB的对象模型非常简单,这种简单性也带来了灵活性,从上面<BR>的几个COM对象也可以看出这一点。下面我们将从应用层角度出发,通<BR>过建立在OLE DB基础上的ADO对象模型结构的分析和使用以帮助读者<BR>进一步理解一致数据访问技术。<BR>&nbsp;&nbsp;&nbsp; 二、ADO对象模型<BR>&nbsp;&nbsp;&nbsp; ADO对象模型定义了一组可编程的自动化对象,可用于Visual Bas<BR>ic、Visual C++、Java以及其他各种支持自动化特性的脚本语言。AD<BR>O最早被用于Microsoft Internet In formation Server中访问数据<BR>库的接口,与一般的数据库接口相比,ADO可更好地用于网络环境,通过<BR>优化技术,它尽可能地降低网络流量;ADO的另一个特性是使用简单,不<BR>仅因为它是一个面向高级用户的数据库接口,更因为它使用了一组简<BR>化的接口用以处理各种数据源。这两个特性使得ADO必将取代RDO和DA<BR>O,成为最终的应用层数据接口标准。<BR>&nbsp;&nbsp;&nbsp; 从图1我们也看到了ADO实际上是OLE DB的应用层接口,这种结构<BR>也为一致的数据访问接口提供了很好的扩展性,而不再局限于特定的<BR>数据源,因此,ADO可以处理各种OLE DB支持的数据源。<BR>&nbsp;&nbsp;&nbsp; 图2是ADO的对象模型图。<BR>图2 ADO对象模型<BR>&nbsp;&nbsp;&nbsp; 在ADO模型中,主体对象只有3个:Connection、Command和Records<BR>et,其他4个集合对象Errors、Properties、Parameters和Fields分别<BR>对应Error、Property、Parameter和Field对象,整个ADO对象模型由<BR>这些对象组成。<BR>&nbsp;&nbsp;&nbsp; 一个典型的ADO应用使用Connection对象建立与数据源的连接,然<BR>后用一个Command对象给出对数据库操作的命令,比如查询或者更新数<BR>据等,而Recordset用于对结果集数据进行维护或者浏览等操作。Comm<BR>and命令所使用的命令语言与底层所对应的OLE DB数据源有关,不同的<BR>数据源可以使用不同的命令语言,对于关系型数据库,通常使用SQL作<BR>为命令语言。<BR>&nbsp;&nbsp;&nbsp; 在Connection、Command和Recordset 3个对象中,Command对象是<BR>个可选对象,它是否有效取决于OLE DB数据提供者是否实现了IComman<BR>d接口。由于OLE DB可提供关系型数据源也可以提供非关系型数据源,<BR>所以在非关系型数据源上使用传统的SQL命令查询数据有可能无效,甚<BR>至Command命令对象也不能使用。<BR>&nbsp;&nbsp;&nbsp; 从结构上看,ADO模型非常简单,但使用上又非常灵活,下面我们先<BR>从单个对象的角度进行讨论:<BR>&nbsp;&nbsp;&nbsp; (1) Connection对象 Connection对象代表与数据源之间的一个<BR>连接,ADO的Connec tion对象封装了OLE DB的数据源对象和会话对象<BR>。根据OLE DB提供者的不同性能,Conne ction对象的特性也有所不同<BR>,所以Connection对象的方法和属性不一定都可以使用。利用Connect<BR>ion对象,我们可以完成以下一些基本设置操作。<BR>&nbsp;&nbsp;&nbsp; a.通过ConnectionString、ConnectionTimeOut和Mode属性设置<BR>连接串、超时信息、访问模式。<BR>&nbsp;&nbsp;&nbsp; b.还可以设置CursorLocation属性以便指定使用客户端游标,以<BR>便在客户程序中使用批处理修改方式。<BR>&nbsp;&nbsp;&nbsp; c.设置连接的缺省数据库属性DefaultDatabase。<BR>&nbsp;&nbsp;&nbsp; d.设置OLE DB提供者的属性Provider。<BR>&nbsp;&nbsp;&nbsp; e.通过Open和Close控制Connection对象与物理数据源的连接。<BR>&nbsp;&nbsp;&nbsp; f.通过Execute方法执行命令。<BR>&nbsp;&nbsp;&nbsp; g.提供事务机制,通过BeginTrans、CommitTrans和RollbackTran<BR>s方法实现事务控制。<BR>&nbsp;&nbsp;&nbsp; h.通过Errors集合属性检查数据源的错误信息。<BR>&nbsp;&nbsp;&nbsp; i.通过OpenSchema方法获取数据库的表信息。<BR>&nbsp;&nbsp;&nbsp; Connection对象是ADO的基本对象之一,它独立于所有其他的对象<BR>。如果我们要对数据库进行查询操作,既可以使用Execute方法,也可<BR>以使用Command对象。使用Execute方法比较简便,但用Command对象可<BR>以保存命令的信息,以便多次查询。<BR>&nbsp;&nbsp;&nbsp; (2) Command对象 Command对象代表一个命令,可以通过其方法执<BR>行针对数据源的有关操作,比如查询、修改等。Command对象的用法如<BR>下:<BR>&nbsp;&nbsp;&nbsp; a.通过CommandText属性设置命令串。<BR>&nbsp;&nbsp;&nbsp; b.通过Parameters集合属性和Parameter对象定义参数化查询或<BR>存储过程的参数。<BR>&nbsp;&nbsp;&nbsp; c.通过Execute方法执行命令,可能的话,返回Recordset对象。<BR>&nbsp;&nbsp;&nbsp; d.在执行命令之前,可通过设置CommandType属性以便优化性能。<BR>&nbsp;&nbsp;&nbsp; e.可以通过Prepared属性指示底层的提供者为当前命令准备一个<BR>编译过的版本,以后再执行时,速度会大大加快。<BR>&nbsp;&nbsp;&nbsp; f.通过CommandTimeOut属性设置命令执行的超时值(以秒为单位)<BR>。<BR>&nbsp;&nbsp;&nbsp; g.可以设置ActiveConnection属性,为命令指定连接串,Command<BR>对象将在内部创建C onnection对象。<BR>&nbsp;&nbsp;&nbsp; h.可以设置Name属性,这样以后可以在相应的Connection对象上<BR>按Name属性指定的方法名执行。<BR>&nbsp;&nbsp;&nbsp; Command对象执行时,既可以通过ActiveConnection属性指定相连<BR>的Connection对象,也可以独立于Connection对象,直接指定连接串,<BR>即使连接串与Connection对象的连接串相同,Command对象仍然使用其<BR>内部的数据源连接。<BR>(3)Recordset对象 Recordset对象代表一个表的记录集或者命令<BR>执行的结果,在记录集中,总是有一个当前的记录。记录集是ADO管理<BR>数据的基本对象,所有的Recordset对象都按照行列方式的表状结构进<BR>行管理,每一行对应一个记录(Record),每一列对应一个域(Field)。<BR>Recordset对象也通过游标对记录进行访问,在ADO中,游标分为以下4种<BR>:<BR>&nbsp;&nbsp;&nbsp; 静态游标提供对数据集的一个静态拷贝,允许各种移动操作,包括<BR>前移、后移等等,但其他用户所做的操作反映不出来。<BR>&nbsp;&nbsp;&nbsp; 动态游标允许各种移动操作,包括前移、后移等等,并且其他用户<BR>所做的操作也可以直接反映出来。<BR>&nbsp;&nbsp;&nbsp; 前向游标允许各种前向移动操作,不能向后移动,并且其他用户所<BR>做的操作也可以直接反映出来。<BR>&nbsp;&nbsp;&nbsp; 键集(keyset)游标 类似于动态游标,也能够看到其他用户所做的<BR>数据修改,但不能看到其他用户新加的记录,也不能访问其他用户删除<BR>的记录。<BR>&nbsp;&nbsp;&nbsp; Recordset对象的用法如下:<BR>&nbsp;&nbsp;&nbsp; a.利用CursorType属性设置游标类型。<BR>&nbsp;&nbsp;&nbsp; b.通过Open方法打开记录集数据,既可以在Open之前对ActiveCon<BR>nection属性赋值, 指定Recordset对象使用连接对象,也可以直接在O<BR>pen方法中指定连接串参数,ADO将创建一个内部连接,即使连接串与外<BR>部的连接对象相同,它也使用新的连接对象。<BR>&nbsp;&nbsp;&nbsp; c.Recordset对象刚打开时,当前记录被定位在首条记录,并且BOF<BR>和EOF标志属性为F alse,如果当前记录集为空记录集,则BOF和EOF标<BR>志属性为True。<BR>&nbsp;&nbsp;&nbsp; d.通过MoveFirst、MoveLast、MoveNext和MovePrevious方法可<BR>以对记录集的游标进行移动操作。如果OLE DB提供者支持相关功能的<BR>话,可以使用AbsolutePosition、Absol utePage和Filter属性对当前<BR>记录重新定位。<BR>&nbsp;&nbsp;&nbsp; e.ADO提供了两种记录修改方式:立即修改和批修改。在立即修改<BR>方式下,一旦调用U pdate方法,则所有对数据的修改立即被写到底层<BR>的数据源。在批修改方式下,可以对多条记录进行修改,然后调用Upda<BR>teBatch方法把所有的修改递交到底层数据源。递交之后,可以用Stat<BR>us属性检查数据冲突。<BR>&nbsp;&nbsp;&nbsp; Recordset对象是ADO数据操作的核心,它既可以作为Connection<BR>对象或Command对象执行特定方法的结果数据集,也可以独立于这两个<BR>对象而使用,由此可以看出ADO对象在使用上的灵活性。<BR>&nbsp;&nbsp;&nbsp; 上面3个对象都包含一个Property对象集合的属性,通过Property<BR>对象可使ADO动态暴露出底层OLE DB提供者的性能。由于并不是所有<BR>的底层提供者都有同样的性能,所以ADO 允许用户动态访问底层提供<BR>者的能力。这样既使得ADO很灵活,又提供了很好的扩展性。<BR>&nbsp;&nbsp;&nbsp; ADO的其他集合对象及其元素对象,都用在特定的上下文环境中,<BR>比如Parameter对象一定要与某个Command对象相联系后,才能真正起<BR>作用。而另外三个对象Field、Error和Property对象只能依附于其父<BR>对象,不能单独创建这些对象。<BR>&nbsp;&nbsp;&nbsp; 三、在多种语言中使用ADO<BR>&nbsp;&nbsp;&nbsp; 以上介绍了ADO的对象模型,现在我们来讨论如何在不同的语言环<BR>境中使用ADO对象。<BR>&nbsp;&nbsp;&nbsp; 因为ADO是作为自动化组件程序实现的,所以我们可以在任何支持<BR>COM和自动化特性的语言环境中使用ADO,比如Visual Basic、Visual <BR>C++、ASP和Java等等,下面分别加以介绍。<BR>&nbsp;&nbsp;&nbsp; 1. 在Visual Basic应用中使用ADO<BR>&nbsp;&nbsp;&nbsp; Visual Basic应用在设计模式和运行模式下都可以创建和使用自<BR>动化对象,在设计模式下,像ADO这样的对象库可以作为内部对象来使<BR>用,我们只需在"Project"菜单下的"Ref erences"命令弹出的对话框<BR>中选中ADO对象库"Microsoft ActiveX Data Objects Libra ry",于<BR>是我们就可以在程序中直接声明或新建ADO对象,举例如下:<BR>&nbsp;&nbsp;&nbsp; Dim cn as New ADODB.Connection<BR>&nbsp;&nbsp;&nbsp; Dim cmd as New ADODB.Command<BR>&nbsp;&nbsp;&nbsp; Dim rs as New ADODB.Recordset<BR>&nbsp;&nbsp;&nbsp; 可以看出,在设计时使用ADO对象非常方便,而且Visual Basic设<BR>计环境中提供的对象浏览器(Object Browser)功能允许用户很方便地<BR>查看ADO对象的属性和方法。<BR>&nbsp;&nbsp;&nbsp; 我们也可以在运行时创建自动化对象,使用Visual Basic的Creat<BR>eObject函数可以创建任意的自动化对象,由于ADO中只有Connection<BR>对象、Command对象和Recordset对象可以被独立创建,所以我们也只<BR>能创建这3种对象,举例如下:<BR>&nbsp;&nbsp;&nbsp; Dim cn<BR>&nbsp;&nbsp;&nbsp; Set rs=CreateObject("ADODB.Connection ")<BR>&nbsp;&nbsp;&nbsp; Dim cmd<BR>&nbsp;&nbsp;&nbsp; Set rs=CreateObject("ADODB.Command")<BR>&nbsp;&nbsp;&nbsp; Dim rs<BR>&nbsp;&nbsp;&nbsp; Set rs=CreateObject("ADODB.Recordset")<BR>&nbsp;&nbsp;&nbsp; 不管是设计模式还是运行模式,调用ADO对象的属性和方法都非常<BR>简单,直接调用即可。<BR>&nbsp;&nbsp;&nbsp; 2. 在ASP的VBScript中使用ADO<BR>&nbsp;&nbsp;&nbsp; ADO对象也可以用于HTML和Active Server Page的VBScript脚本<BR>代码,VBScript脚本代码与Visual Basic的代码很类似,它们内嵌在HT<BR>ML或ASP文件的特定标记对内部。但VB Script引擎比Visual Basic的<BR>设计环境或运行库在功能上还是要弱一些,首先,在VBScri pt代码中,<BR>没有与设计环境类似的用法,VBScript引擎不能装入ADO类型库,所以<BR>不能使用New操作符创建ADO对象,但可以使用CreateObject函数创建<BR>对象;其次,ADO对象库中用到的常量只能通过包含文件引入,随ADO一<BR>起提供的Adovbs.inc文件包含所有ADO常量的定义,我们可在脚本代码<BR>中直接包含此文件。<BR>&nbsp;&nbsp;&nbsp; 因此,为了在VBScript代码中使用ADO,首先要包含Adovbs.inc文<BR>件,然后使用Create Object函数创建ADO对象,以后就可以调用这些对<BR>象的属性或方法了。下面的例子显示了在ASP文件中用ADO列出数据表<BR>中所有作者的姓名和职称,代码如下:<BR>&nbsp;&nbsp;&nbsp; Using ADO in a Visual Basic Script Web Page<BR>&nbsp;&nbsp;&nbsp; Using ADO in a Visual Basic Script<BR>&nbsp;&nbsp;&nbsp; Web Page<BR>&nbsp;&nbsp;&nbsp; myConnection.Open "DSN=MySamples;UID=sa"<BR>&nbsp;&nbsp;&nbsp; SQLQuery = "select AuthorName, Title from AuthorDB"<BR>&nbsp;&nbsp;&nbsp; set rs = myConnection.Execute(SQLQuery)%<BR>&nbsp;&nbsp;&nbsp; WIDTH=200<BR>&nbsp;&nbsp;&nbsp; Title ID<BR>&nbsp;&nbsp;&nbsp; SIZE=1<BR>&nbsp;&nbsp;&nbsp; Title<BR>&nbsp;&nbsp;&nbsp; "arial narrow" size=1<BR>&nbsp;&nbsp;&nbsp; "arial narrow" size=1<BR>&nbsp;&nbsp;&nbsp; 3. 在Visual C++中使用ADO<BR>&nbsp;&nbsp;&nbsp; 在Visual C++中使用ADO有多种方法,第一种方法是我们使用CoCr<BR>eateInstance函数创建ADO对象,并得到对象的IDispatch接口指针,然<BR>后调用其Invoke函数,用这种方法需要我们自己处理参数和返回值,AD<BR>O提供了Adoid.h和Adoint.h头文件分别定义了ADO对象的CLSID和接口<BR>ID;第二种方法是利用#import编译指示符(在Visual C++ 5.0及以后<BR>的版本中可以使用),可以方便地使用ADO对象;第三种方法是利用MFC(<BR>Microsoft Foundation C lass)库提供的IDispatch接口封装类COleD<BR>ispatchDriver创建和调用ADO对象。<BR>&nbsp;&nbsp;&nbsp; 下面的代码显示了在Visual C++创建数据源连接的过程:<BR>&nbsp;&nbsp;&nbsp; GUID connectionCLSID;<BR>&nbsp;&nbsp;&nbsp; HRESULT hResult = ::CLSIDFromProgID(L"ADODB.Connection",<BR>&nbsp;&nbsp;&nbsp; &amp;connectionCLSID);<BR>&nbsp;&nbsp;&nbsp; if (FAILED(hResult))<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; ......<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; IDispatch *pDispatch = NULL;<BR>&nbsp;&nbsp;&nbsp; hResult = CoCreateInstance(connectionCLSID, NULL,<BR>&nbsp;&nbsp;&nbsp; CLSCTX_SERVER, IID_IDispatch, (void **)&amp;pDispatch);<BR>&nbsp;&nbsp;&nbsp; if (FAILED(hResult))<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; ......<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; COleDispatchDriver driver;<BR>&nbsp;&nbsp;&nbsp; driver.AttachDispatch(pDispatch, FALSE);<BR>&nbsp;&nbsp;&nbsp; TRY<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; BYTE parms =VTS_BSTR;<BR>&nbsp;&nbsp;&nbsp; driver.InvokeHelper(0xa, DISPATCH_METHOD,<BR>&nbsp;&nbsp;&nbsp; VT_EMPTY, &amp;hResult, parms,L"Provider=SQLOLEDB;<BR>&nbsp;&nbsp;&nbsp; User ID=sa;Password=;" L"Initial Catalog=LEAVES;<BR>&nbsp;&nbsp;&nbsp; Data Source=NetTestServer");<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; END_TRY<BR>&nbsp;&nbsp;&nbsp; driver.DetachDispatch();<BR>&nbsp;&nbsp;&nbsp; ......<BR>&nbsp;&nbsp;&nbsp; 4. 在Java中使用ADO<BR>&nbsp;&nbsp;&nbsp; 在Java程序中可以引入ADODB类,然后声明ADO变量,也可以使用ne<BR>w操作符创建ADO变量。下面的代码说明了如何在Java中打开与数据源<BR>连接:<BR>&nbsp;&nbsp;&nbsp; import msado10.*;<BR>&nbsp;&nbsp;&nbsp; _Connection m_conn = null;<BR>&nbsp;&nbsp;&nbsp; _Recordset m_rs = null;<BR>&nbsp;&nbsp;&nbsp; _Command m_cmd = null;<BR>&nbsp;&nbsp;&nbsp; void OpenConnection()<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; String s;<BR>&nbsp;&nbsp;&nbsp; Properties properties;<BR>&nbsp;&nbsp;&nbsp; try<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; properties = m_conn.getProperties();<BR>&nbsp;&nbsp;&nbsp; m_conn.Open("dsn=MySamples", "sa", "");<BR>&nbsp;&nbsp;&nbsp; properties = null;<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; catch (Exception e)<BR>&nbsp;&nbsp;&nbsp; { System.out.println("\nUnable to make a connection \n")<BR>;<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; }</FONT><IMG height=1 src="http://www.moon-soft.com/doc/down_info.asp?id=14683" width=1 border=0><BR></TD></TR></TBODY></TABLE>]]></description>
</item><item>
<title><![CDATA[[转载]VC++ ADO开发实践之六]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=fishyqd&amp;id=13050</link>
<author>fishyqd</author>
<pubDate>2006/3/30 21:40:50</pubDate>
<description><![CDATA[<FONT size=2>ActiveX数据对象（ADO）是OLE DB上面的高层数据库API。我们在C＋＋程序中也可以调用ADO。本文将在VC 6.0环境下做一个小小的例子解释如何使用ADO。 </FONT>
<P><FONT size=2>　　1. 生成应用程序框架并初始化OLE/COM库环境 </FONT></P>
<P><FONT size=2>　　创建一个标准的MFC AppWizard(exe)应用程序，然后在应用程序类的InitInstance函数中初始化OLE/COM库（因为ADO库是一个COM DLL库）。 </FONT></P>
<P><FONT size=2>　　BOOL CADOTestApp::InitInstance() </FONT></P>
<P><FONT size=2>　　{ //初始化OLE/COM库环境 </FONT></P>
<P><FONT size=2>AfxOleInit();} </FONT></P>
<P><FONT size=2>　　2. 引入ADO库文件 </FONT></P>
<P><FONT size=2>　　使用ADO前必须在工程的stdafx.h文件里用直接引入符号＃import引入ADO库文件，以使编译器能正确编译。代码如下： </FONT></P>
<P><FONT size=2>　　 ＃include 〈comdef.h〉 </FONT></P>
<P><FONT size=2>　　 ＃import "c:\program files\common files\system\ado\msado15.dll"</FONT></P>
<P><FONT size=2>　　 no_namespace </FONT></P>
<P><FONT size=2>　　 rename ("EOF","adoEOF") </FONT></P>
<P><FONT size=2>　　头文件comdef.h使我们的应用程序能够使用Visual C＋＋中的一些特殊COM支持类，这些类使得处理OLE自治更为容易一些，OLE自治是ADO使用的数据类型。后三行使用＃import指令在我们的应用程序中输入ADO类库定义。 </FONT></P>
<P><FONT size=2>　　ADO类的定义是作为一种资源存储在ADO DLL(msado15.dll）中，在其内部称为类型库。类型库描述了自治接口，以及C＋＋使用的COM vtable接口。当使用＃import指令时，在运行时Visual C＋＋需要从ADO DLL中读取这个类型库，并以此创建一组C＋＋头文件。这些头文件具有.tli 和.tlh扩展名，读者可以在项目的目录下找到这两个文件。在C＋＋程序代码中调用的ADO类要在这些文件中定义。 </FONT></P>
<P><FONT size=2>　　程序的第三行指示ADO对象不使用名称空间。在有些应用程序中，由于应用程序中的对象与ADO中的对象之间可能会出现命名冲突，所以有必要使用名称空间。如果要使用名称空间，则可把第三行程序修改为： rename_namespace("AdoNS")。第四行代码将ADO中的EOF(文件结束)更名为adoEOF，以避免与定义了自己的EOF的其他库冲突。 </FONT></P>
<P><FONT size=2>　　3．利用智能指针进行数据库操作 </FONT></P>
<P><FONT size=2>　　在CaboutDlg头文件中定义两个ADO智能指针类实例,并在对话框中加入一个ListCtrl。 </FONT></P>
<P><FONT size=2>_ConnectionPtr m_pConnection; </FONT></P>
<P><FONT size=2>_RecordsetPtr m_pRecordset; </FONT></P>
<P><FONT size=2>　　ClistCtrl m_List; </FONT></P>
<P><FONT size=2>　　ADO库包含三个智能指针:_ConnectionPtr、_CommandPtr和_RecordsetPtr。 </FONT></P>
<P><FONT size=2>_ConnectionPtr通常被用来创建一个数据连接或执行一条不返回任何结果的SQL语句，如一个存储过程。 </FONT></P>
<P><FONT size=2>_CommandPtr返回一个记录集。它提供了一种简单的方法来执行返回记录集的存储过程和SQL语句。在使用_CommandPtr接口时，可以利用全局_ConnectionPtr接口，也可以在_CommandPtr接口里直接使用连接串。 </FONT></P>
<P><FONT size=2>_RecordsetPtr是一个记录集对象。与以上两种对象相比，它对记录集提供了更多的控制功能，如记录锁定、游标控制等。 </FONT></P>
<P><FONT size=2>　　在OnInitDialog()中加入以下代码: </FONT></P>
<P><FONT size=2>　　BOOL CAboutDlg::OnInitDialog() </FONT></P>
<P><FONT size=2>　　{ </FONT></P>
<P><FONT size=2>CDialog::OnInitDialog(); </FONT></P>
<P><FONT size=2>_variant_t TheValue; </FONT></P>
<P><FONT size=2>m_List.ResetContent(); </FONT></P>
<P><FONT size=2>　　m_pConnection.CreateInstance(_uuidof(Connection)); </FONT></P>
<P><FONT size=2>　　m_pRecordset.CreateInstance(_uuidof(Recordset)); </FONT></P>
<P><FONT size=2>　　try{ </FONT></P>
<P><FONT size=2>m_pConnection-&gt;Open("DSN=ADOTest","","",0); //连接叫作ADOTest的ODBC数据源 </FONT></P>
<P><FONT size=2>m_pRecordset-&gt;Open("SELECT * FROM BlockDefine",(IDispatch*)m_pConnection, <BR>adOpenDynamic,<BR>adLockOptimistic,<BR>adCmdText); </FONT></P>
<P><FONT size=2>　　//执行SQL语句得到一个记录集 </FONT></P>
<P><FONT size=2>　　 while(!m_pRecordset-&gt;adoEOF) </FONT></P>
<P><FONT size=2>　　//遍历所有记录 </FONT></P>
<P><FONT size=2>　　 { </FONT></P>
<P><FONT size=2>　　 TheValue = m_pRecordset-&gt;GetCollect("BlockIndex");</FONT></P>
<P><FONT size=2>　　//得到字段BlockIndex的值 </FONT></P>
<P><FONT size=2>　　 if(TheValue.vt!=VT_NULL) </FONT></P>
<P><FONT size=2>　　 m_List.AddString((char*)_bstr_t(TheValue)); //将该值加入到列表控件中 </FONT></P>
<P><FONT size=2>　　 m_pRecordset-&gt;MoveNext(); </FONT></P>
<P><FONT size=2>　　} </FONT></P>
<P><FONT size=2>　　 m_pRecordset-&gt;Close(); </FONT></P>
<P><FONT size=2>m_pConnection-&gt;Close(); </FONT></P>
<P><FONT size=2>　　 } </FONT></P>
<P><FONT size=2>　　 catch(_com_error e) //异常处理 </FONT></P>
<P><FONT size=2>　　 { </FONT></P>
<P><FONT size=2>AfxMessageBox(e-&gt;ErrorMessage()); </FONT></P>
<P><FONT size=2>　　} </FONT></P>
<P><FONT size=2>　　m_pRecordset = NULL; </FONT></P>
<P><FONT size=2>m_pConnection = NULL; </FONT></P>
<P><FONT size=2>　　return TRUE; // return TRUE unless you set the focus to a control </FONT></P>
<P><FONT size=2>　　} </FONT></P>
<P><FONT size=2>　　程序中通过_variant_t和_bstr_t转换COM对象和C＋＋类型的数据, _variant_t类封装了OLE自治VARIANT数据类型。在C＋＋中使用_variant_t类要比直接使用VARIANT数据类型容易得多。 </FONT></P>
<P><FONT size=2>　　好，编译后该程序就能运行了，但记住运行前要创建一个叫ADOTest的ODBC数据源。该程序将把表BlockDefine中的BlockIndex字段值显示在列表控件中。</FONT> </P>]]></description>
</item><item>
<title><![CDATA[[转载]VC++ ADO开发实践之五]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=fishyqd&amp;id=13049</link>
<author>fishyqd</author>
<pubDate>2006/3/30 21:38:53</pubDate>
<description><![CDATA[
<DIV>转载自：<A href="http://www.csdn.net">www.csdn.net</A></DIV>
<DIV>
<P><FONT size=2>一、ADO概述</FONT></P>
<P><FONT size=2>ADO是Microsoft为最新和最强大的数据访问范例 OLE DB 而设计的，是一个便于使用的应用程序层接口。ADO 使您能够编写应用程序以通过 OLE.DB 提供者访问和操作数据库服务器中的数据。ADO 最主要的优点是易于使用、速度快、内存支出少和磁盘遗迹小。ADO 在关键的应用方案中使用最少的网络流量，并且在前端和数据源之间使用最少的层数，所有这些都是为了提供轻量、高性能的接口。之所以称为 ADO，是用了一个比较熟悉的暗喻，OLE 自动化接口。</FONT></P>
<P><FONT size=2>OLE DB是一组”组件对象模型”(COM) 接口，是新的数据库低层接口，它封装了ODBC的功能，并以统一的方式访问存储在不同信息源中的数据。OLE DB是Microsoft UDA(Universal Data Access)策略的技术基础。OLE DB 为任何数据源提供了高性能的访问，这些数据源包括关系和非关系数据库、电子邮件和文件系统、文本和图形、自定义业务对象等等。也就是说，OLE DB 并不局限于 ISAM、Jet 甚至关系数据源，它能够处理任何类型的数据，而不考虑它们的格式和存储方法。在实际应用中，这种多样性意味着可以访问驻留在 Excel 电子数据表、文本文件、电子邮件/目录服务甚至邮件服务器，诸如 Microsoft Exchange 中的数据。但是，OLE DB 应用程序编程接口的目的是为各种应用程序提供最佳的功能，它并不符合简单化的要求。您需要的API 应该是一座连接应用程序和 OLE DB 的桥梁，这就是 ActiveX Data Objects (ADO)。</FONT></P>
<P><FONT size=2>二、在VC中使用ADO</FONT></P>
<P><FONT size=2>1、引入ADO库文件</FONT></P>
<P><FONT size=2>使用ADO前必须在工程的stdafx.h文件里用直接引入符号#import引入ADO库文件,以使编译器能正确编译。代码如下所示：</FONT></P>
<P><FONT size=2>代码1：用#import引入ADO库文件</FONT></P>
<P><FONT size=2>#import "c:\program files\common files\system\ado\msado15.dll" </FONT></P>
<P><FONT size=2>no_namespaces rename("EOF" adoEOF")</FONT></P>
<P><FONT size=2>这行语句声明在工程中使用ADO，但不使用ADO的名字空间，并且为了避免常数冲突，将常数EOF改名为adoEOF。现在不需添加另外的头文件，就可以使用ADO接口了。</FONT></P>
<P><FONT size=2>2、初始化OLE/COM库环境</FONT></P>
<P><FONT size=2>必须注意的是，ADO库是一组COM动态库，这意味应用程序在调用ADO前，必须初始化OLE/COM库环境。在MFC应用程序里，一个比较好的方法是在应用程序主类的InitInstance成员函数里初始化OLE/COM库环境。</FONT></P>
<P><FONT size=2>　</FONT></P>
<P><FONT size=2>代码2：初始化OLE/COM库环境</FONT></P>
<P><FONT size=2>BOOL CADOApp：：InitInstance()</FONT></P>
<P><FONT size=2>{</FONT></P>
<P><FONT size=2>if(!AfxOleInit())</FONT></P>
<P><FONT size=2>　</FONT></P>
<P><FONT size=2>{</FONT></P>
<P><FONT size=2>AfxMessageBox(“OLE初始化出错!”);</FONT></P>
<P><FONT size=2>return FALSE;</FONT></P>
<P><FONT size=2>} </FONT></P>
<P><FONT size=2>……</FONT></P>
<P><FONT size=2>　</FONT></P>
<P><FONT size=2>}</FONT></P>
<P><FONT size=2>函数AfxOleInit在每次应用程序启动时初始化OLE/COM库环境。</FONT></P>
<P><FONT size=2>同DAO和CDatabase一样，ADO由几个接口组成：</FONT></P>
<P><FONT size=2>_ConnectionPtr,_CommandPtr和_RecordsetPtr.</FONT></P>
<P><FONT size=2>不同于DAO和Cdatabase的是，ADO基于COM的接口，因此，假如你没有接触过COM，你应该在使用ADO前先找有关书籍了解一下COM。</FONT></P>
<P><FONT size=2>3、ADO接口简介</FONT></P>
<P><FONT size=2>ADO库包含三个基本接口:_ConnectionPtr接口、_CommandPtr接口和_RecordsetPtr接口。</FONT></P>
<P><FONT size=2>_ConnectionPtr接口返回一个记录集或一个空指针。通常使用它来创建一个数据连接或执行一条不返回任何结果的SQL语句，如一个存储过程。使用_ConnectionPtr接口返回一个记录集不是一个好的使用方法。通常同CDatabase一样，使用它创建一个数据连接，然后使用其它对象执行数据输入输出操作。</FONT></P>
<P><FONT size=2>_CommandPtr接口返回一个记录集。它提供了一种简单的方法来执行返回记录集的存储过程和SQL语句。在使用_CommandPtr接口时，你可以利用全局_ConnectionPtr接口，也可以在_CommandPtr接口里直接使用连接串。如果你只执行一次或几次数据访问操作，后者是比较好的选择。但如果你要频繁访问数据库，并要返回很多记录集，那么，你应该使用全局_ConnectionPtr接口创建一个数据连接，然后使用_CommandPtr接口执行存储过程和SQL语句。</FONT></P>
<P><FONT size=2>_RecordsetPtr是一个记录集对象。与以上两种对象相比，它对记录集提供了更多的控制功能，如记录锁定，游标控制等。同_CommandPtr接口一样，它不一定要使用一个已经创建的数据连接，可以用一个连接串代替连接指针赋给_RecordsetPtr的connection成员变量，让它自己创建数据连接。如果你要使用多个记录集，最好的方法是同Command对象一样使用已经创建了数据连接的全局_ConnectionPtr接口，然后使用_RecordsetPtr执行存储过程和SQL语句。</FONT></P>
<P><FONT size=2>　</FONT></P>
<P><FONT size=2>4、使用_ConnectionPtr接口</FONT></P>
<P><FONT size=2>_ConnectionPtr是一个连接接口，它类似于CDatabase和CDaoDatabase。它们的工作原理相似。首先创建一个_ConnectionPtr接口实例，接着指向并打开一个ODBC数据源或OLE DB数据提供者(Provider)。以下代码和CDaoDatabase分别创建一个基于DSN和非DSN的数据连接。</FONT></P>
<P><FONT size=2>　</FONT></P>
<P><FONT size=2>代码3:使用CDaoDatabase（基于DSN）</FONT></P>
<P><FONT size=2>CDaoDatabase MyDb = new CDaoDatabase();</FONT></P>
<P><FONT size=2>MyDb.Open(NULL,FALSE,FALSE,"ODBC;DSN=samp;UID=admin;PWD=admin");</FONT></P>
<P><FONT size=2>　</FONT></P>
<P><FONT size=2>　</FONT></P>
<P><FONT size=2>代码4:使用CDaoDatabase（基于非DSN）</FONT></P>
<P><FONT size=2>CDaoDatabase MyDb = new CDaoDatabase();</FONT></P>
<P><FONT size=2>MyDb.Open(NULL,FALSE,FALSE,"ODBC;DRIVER={SQL Server};SERVER=server;</FONT></P>
<P><FONT size=2>DATABASE=samp;UID=admin;PWD=admin");</FONT></P>
<P><FONT size=2>　</FONT></P>
<P><FONT size=2>　</FONT></P>
<P><FONT size=2>代码5:使用_ConnectionPtr(基于DSN)</FONT></P>
<P><FONT size=2>_ConnectionPtr MyDb;</FONT></P>
<P><FONT size=2>MyDb.CreateInstance(__uuidof(Connection));</FONT></P>
<P><FONT size=2>MyDb-&gt;Open("DSN=samp;UID=admin;PWD=admin","","",-1);</FONT></P>
<P><FONT size=2>　</FONT></P>
<P><FONT size=2>　</FONT></P>
<P><FONT size=2>代码6:使用_ConnectionPtr (基于非DSN)</FONT></P>
<P><FONT size=2>_ConnectionPtr MyDb;</FONT></P>
<P><FONT size=2>MyDb.CreateInstance(__uuidof(Connection));</FONT></P>
<P><FONT size=2>MyDb-&gt;Open("Provider=SQLOLEDB;SERVER=server;DATABASE=samp;UID=admin;</FONT></P>
<P><FONT size=2>PWD=admin","","",-1);</FONT></P>
<P><FONT size=2>　</FONT></P>
<P><FONT size=2>5、使用_RecordsetPtr接口</FONT></P>
<P><FONT size=2>_RecordsetPtr接口的使用方法和CDaoDatabase类似，通过以下代码的比较，你会发现使用_RecordsetPtr接口非常简单(以下代码使用上面已经创建的数据连接):</FONT></P>
<P><FONT size=2>　</FONT></P>
<P><FONT size=2>代码7:使用CDaoDatabase执行SQL语句</FONT></P>
<P><FONT size=2>CDaoRecordset MySet = new CDaoRecordset(MyDb);</FONT></P>
<P><FONT size=2>MySet-&gt;Open(AFX_DAO_USE_DEFAULT_TYPE,"SELECT * FROM t_samp");</FONT></P>
<P><FONT size=2>Now using ADO:</FONT></P>
<P><FONT size=2>　</FONT></P>
<P><FONT size=2>　</FONT></P>
<P><FONT size=2>代码8:使用_RecordsetPtr执行SQL语句</FONT></P>
<P><FONT size=2>_RecordsetPtr MySet;</FONT></P>
<P><FONT size=2>MySet.CreateInstance(__uuidof(Recordset));</FONT></P>
<P><FONT size=2>MySet-&gt;Open("SELECT * FROM some_table",</FONT></P>
<P><FONT size=2>MyDb.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);</FONT></P>
<P><FONT size=2>现在我们已经有了一个数据连接和一个记录集，接下来就可以使用数据了。从以下代码可以看到，使用ADO的_RecordsetPtr接口，就不需要象DAO那样频繁地使用大而复杂的数据结构VARIANT，并强制转换各种数据类型了，这也是ADO的优点之一。假定程序有一个名称为m_List的的ListBox控件，下面代码我们用_RecordsetPtr接口获取记录集数据并填充这个ListBox控件：</FONT></P>
<P><FONT size=2>　</FONT></P>
<P><FONT size=2>代码9:使用DAO访问数据</FONT></P>
<P><FONT size=2>VARIANT * vFieldValue;</FONT></P>
<P><FONT size=2>COleVariant covFieldValue;</FONT></P>
<P><FONT size=2>CString Holder;</FONT></P>
<P><FONT size=2>while(!MySet-&gt;IsEOF())</FONT></P>
<P><FONT size=2>{</FONT></P>
<P><FONT size=2>MySet-&gt;GetFieldValue("FIELD_1", covFieldValue);</FONT></P>
<P><FONT size=2>vFieldValue = (LPVARIANT)covFieldValue;</FONT></P>
<P><FONT size=2>if(vFieldValue-&gt;vt!-VT_NULL)</FONT></P>
<P><FONT size=2>{</FONT></P>
<P><FONT size=2>Holder.Format("%s",vFieldValue-&gt;pbVal);</FONT></P>
<P><FONT size=2>m_List.AddString(Holder);</FONT></P>
<P><FONT size=2>　</FONT></P>
<P><FONT size=2>}</FONT></P>
<P><FONT size=2>MySet.MoveNext();</FONT></P>
<P><FONT size=2>　</FONT></P>
<P><FONT size=2>}</FONT></P></DIV>]]></description>
</item><item>
<title><![CDATA[[转载]VC++ ADO开发实践之四]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=fishyqd&amp;id=13048</link>
<author>fishyqd</author>
<pubDate>2006/3/30 21:37:27</pubDate>
<description><![CDATA[<A>出处：</A><A href="http://www.csdn.net/" target=_blank><SPAN class=px12>CSDN</SPAN></A><A> 作者: zswzwy <BR></A>
<P><FONT size=2>在VC中使用ADO开发数据库应用程序&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>1.引入ADO库文件<BR>使用ADO前必须在工程的stdafx.h文件里用直接引入符号＃import引入ADO库文件，<BR>以使编译器能正确编译。代码如下所示：<BR>＃import "c:\program files\common files\system\ado\msado15.dll"<BR>no—namespaces rename("EOF" adoEOF")<BR>这行语句声明在工程中使用ADO，但不使用ADO的名字空间，并且为了避免冲突，将EOF改<BR>名为adoEOF。</FONT></P>
<P><FONT size=2>2.初始化OLE/COM库环境<BR>必须注意的是，ADO库是一组COM动态库，这意味应用程序在调用ADO前，必须初始<BR>化OLE/COM库环境。在MFC应用程序里，一个比较好的方法是在应用程序主类的<BR>InitInstance成员函数里初始化OLE/COM库环境。</FONT></P>
<P><FONT size=2>　　//初始化OLE/COM库环境</FONT></P>
<P><FONT size=2>　 BOOL CADOApp::InitInstance()<BR>　　{ <BR>if(!AfxOleInit())<BR>{ <BR>AfxMessageBox("OLE初始化出错!");<BR>return FALSE; <BR>}<BR>......<BR>}</FONT></P>
<P><FONT size=2>函数AfxOleInit在每次应用程序启动时初始化OLE/COM库环境。</FONT></P>
<P><FONT size=2>3.ADO接口简介<BR>ADO库包含三个基本接口:<BR>__ConnectionPtr接口、<BR>__CommandPtr接口和、<BR>__RecordsetPtr接口,</FONT></P>
<P><FONT size=2>__ConnectionPtr接口返回一个记录集或一个空指针。通常使用它来创建一个数据连接或<BR>执行一条不返回任何结果的SQL语句，如一个存储过程。用__ConnectionPtr接口返回一<BR>个记录集不是一个好的使用方法。通常同CDatabase一样，使用它创建一个数据连接，然<BR>后使用其它对象执行数据输入输出操作。</FONT></P>
<P><FONT size=2>__CommandPtr接口返回一个记录集。它提供了一种简单的方法来执行返回记录集的存储<BR>过程和SQL语句。在使用__CommandPtr接口时，可以利用全局__ConnectionPtr接口，也<BR>可以在__CommandPtr接口里直接使用连接串。如果只执行一次或几次数据访问操作，后<BR>者是比较好的选择。但如果要频繁访问数据库，并要返回很多记录集，那么，应该使用<BR>全局__ConnectionPtr接口创建一个数据连接，然后使用__CommandPtr接口执行存储过程<BR>和SQL语句。</FONT></P>
<P><FONT size=2>__RecordsetPtr是一个记录集对象。与以上两种对象相比，它对记录集提供了更多<BR>的控制功能，如记录锁定，游标控制等。同__CommandPtr接口一样，它不一定要使用一<BR>个已经创建的数据连接，可以用一个连接串代替连接指针赋给__RecordsetPtr的<BR>connection成员变量，让它自己创建数据连接。如果要使用多个记录集，最好的方法是<BR>同Command对象一样使用已经创建了数据连接的全局—ConnectionPtr接口，然后使用<BR>__RecordsetPtr执行存储过程和SQL语句。</FONT></P>
<P><FONT size=2>4.使用__ConnectionPtr接口</FONT></P>
<P><FONT size=2>__ConnectionPtr是一个连接接口，它类似于CDatabase和CDaoDatabase。首先创建一个<BR>__ConnectionPtr接口实例，接着指向并打开一个ODBC数据源或OLE DB数据提供者<BR>(Provider)。以下代码分别创建一个基于DSN和非DSN的数据连接。</FONT></P>
<P><FONT size=2>　　//使用__ConnectionPtr(基于DSN)</FONT></P>
<P><FONT size=2>　　__ConnectionPtr MyDb;</FONT></P>
<P><FONT size=2>　　MyDb.CreateInstance(__uuidof(Connection));</FONT></P>
<P><FONT size=2>　　MyDb－〉Open("DSN=samp;UID=admin;PWD=admin","","",－1);</FONT></P>
<P><FONT size=2>　　//使用—ConnectionPtr (基于非DSN)</FONT></P>
<P><FONT size=2>　　__ConnectionPtr MyDb;</FONT></P>
<P><FONT size=2>　　MyDb.CreateInstance(__uuidof(Connection));</FONT></P>
<P><FONT size=2>　　MyDb－〉Open("Provider=SQLOLEDB;SERVER=server;DATABASE=samp;UID=admin;</FONT></P>
<P><FONT size=2>　　PWD=admin","","",－1);</FONT></P>
<P><BR><FONT size=2>5.使用__RecordsetPtr接口<BR>__RecordsetPtr接口的使用方法和CDaoDatabase类似，通过以下代码的比较，你会发现<BR>使用—RecordsetPtr接口非常简单(以下代码使用上面已经创建的数据连接)：</FONT></P>
<P><FONT size=2>　　//使用CDaoDatabase执行SQL语句</FONT></P>
<P><FONT size=2>　　CDaoRecordset MySet = new CDaoRecordset(MyDb);</FONT></P>
<P><FONT size=2>　　MySet－〉Open(AFX__DAO__USE__DEFAULT__TYPE,"SELECT  FROM t__samp");</FONT></P>
<P><FONT size=2>　　Now using ADO:</FONT></P>
<P><FONT size=2>　　//使用__RecordsetPtr执行SQL语句</FONT></P>
<P><FONT size=2>　　__RecordsetPtr MySet;</FONT></P>
<P><FONT size=2>　　MySet.CreateInstance(__uuidof(Recordset));</FONT></P>
<P><FONT size=2>　　MySet－〉Open("SELECT  FROM some__table",</FONT></P>
<P><FONT size=2>　　MyDb.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);</FONT></P>
<P><FONT size=2>　　现在我们已经有了一个数据连接和一个记录集，接下来就可以使用数据了。从以下<BR>代码可以看到，使用ADO的__RecordsetPtr接口，就不需要像DAO那样频繁地使用大而复<BR>杂的数据结构VARIANT，并强制转换各种数据类型了，这也是ADO的优点之一。假定程序<BR>有一个名称为m__List的ListBox控件，下面代码我们用__RecordsetPtr接口获取记录集<BR>数据并填充这个ListBox控件：</FONT></P>
<P><FONT size=2>　　//使用ADO访问数据</FONT></P>
<P><FONT size=2>　　__variant__t Holder</FONT></P>
<P><FONT size=2>　　try{while(!MySet－〉adoEOF)</FONT></P>
<P><FONT size=2>　　{ Holder = MySet－〉GetCollect("FIELD__1");</FONT></P>
<P><FONT size=2>　　if(Holder.vt!=VT__NULL)</FONT></P>
<P><FONT size=2>　　m__List.AddString((char)__bstr__t(Holder));</FONT></P>
<P><FONT size=2>　　MySet－〉MoveNext();} }</FONT></P>
<P><FONT size=2>　　catch(__com__error  e)</FONT></P>
<P><FONT size=2>　　{ CString Error = e－〉ErrorMessage();</FONT></P>
<P><FONT size=2>　　 AfxMessageBox(e－〉ErrorMessage());</FONT></P>
<P><FONT size=2>　　} catch(...)</FONT></P>
<P><FONT size=2>　　{ MessageBox("ADO发生错误!");}</FONT></P>
<P><FONT size=2>　　必须始终在代码中用try和catch来捕获ADO错误,否则ADO错误会使你的应用程序崩<BR>溃。当ADO发生运行错误时(如数据库不存在)，OLE DB数据提供者将自动创建一个<BR>__com__error对象，并将有关错误信息填充到这个对象的成员变量。</FONT></P>
<P><FONT size=2>6.使用__CommandPtr接口<BR>__CommandPtr接口返回一个Recordset对象，并且提供了更多的记录集控制功能，以下代<BR>码示例使用__CommandPtr接口的方法：</FONT></P>
<P><FONT size=2>　　//使用__CommandPtr接口获取数据</FONT></P>
<P><FONT size=2>　　__CommandPtr pCommand;</FONT></P>
<P><FONT size=2>　　__RecordsetPtr MySet;</FONT></P>
<P><FONT size=2>　　pCommand.CreateInstance(__uuidof(Command));</FONT></P>
<P><FONT size=2>　　pCommand－〉ActiveConnection=MyDb;</FONT></P>
<P><FONT size=2>　　pCommand－〉CommandText="select  from some—table";</FONT></P>
<P><FONT size=2>　　pCommand－〉CommandType=adCmdText;</FONT></P>
<P><FONT size=2>　　pCommand－〉Parameters－〉Refresh();</FONT></P>
<P><FONT size=2>　　MySet=pCommand－〉Execute(NULL,NULL,adCmdUnknown);</FONT></P>
<P><FONT size=2>　　__variant__t TheValue = MySet－〉GetCollect("FIELD__1");</FONT></P>
<P><FONT size=2>　　CString sValue=(char)__bstr__t(TheValue);</FONT></P>
<P><FONT size=2>7.关于数据类型转换<BR>　　由于COM对象是跨平台的，它使用了一种通用的方法来处理各种类型的数据，因此<BR>CString 类和COM对象是不兼容的，我们需要一组API来转换COM对象和C＋＋类型的数<BR>据。__vatiant__t和__bstr__t就是这样两种对象。它们提供了通用的方法转换COM对象<BR>和C＋＋类型的数据。&nbsp; </FONT></P>]]></description>
</item><item>
<title><![CDATA[[转载]C++ ADO开发实践之三]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=fishyqd&amp;id=13047</link>
<author>fishyqd</author>
<pubDate>2006/3/30 21:35:51</pubDate>
<description><![CDATA[
<P><FONT size=2>在Visual C++中如何利用UDL文件来建立ADO连接&nbsp;<BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp; 使用通用数据连接文件（*.UDL，以下简称文件）来创建ADO连接，可以和ODBC一样可视化地定义要连接的数据源，从而实现数据访问的透明性。 </FONT></P>
<P><BR><FONT size=2>1.使用UDL文件来创建ADO连接 <BR>创建ADO的连接，首先要设置ADO连接对象的ConnectionString属性，该属性提供所要连接的数据库类型、数据所处服务器、要访问的数据库和数据库访问的安全认证信息。比较专业的方法是在ConnectionString中直接提供以上信息，下面是访问不同类型数据源设置ConnectionString的标准： <BR>访问ODBC数据 <BR>"Provider=MSDASQL;DSN=dsnName;UID=userName;PWD=userPassword;" <BR>访问ORACLE数据库 <BR>"Provider=MSDAORA;Data Source=serverName;User ID=userName; Password=userPassword;" <BR>访问MS SQL数据库 <BR>"Provider=SQLOLEDB;Data Source=serverName;Initial Catalog=databaseName; User ID=userName;Password=userPassword;" <BR>访问ACCESS 数据库 <BR>"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=databaseName;User ID=userName;Password=userPassword;" <BR>上述的连接属性设置标准随着数据源的类型不同而变化，软件用户常常不习惯这种设置方式，都希望有可视化的数据源设置方法。为此Microsoft提供了通用数据连接文件（.UDL）来建立和测试ADO连接属性。ADO连接对象可以很方便地使用UDL文件来连接数据源，下面例子使用my_data1.udl来创建ADO连接。 <BR>_ConnectionPtr m_pDBConn; <BR>m_pDBConn.CreateInstance(__uuidof(Connection)); <BR>m_pDBConn-&gt;ConnectionString ="File Name=c:\mydir\my_data1.udl"; <BR>m_pDBConn-&gt;Open("","","",NULL); <BR>这样一来无论数据源如何变化，在软件中都可以用统一的方法编程。当数据源改变时，只要双击相应的udl文件即可可视化地设置数据源，无需更改软件。 <BR>因为ADO是COM接口，为了软件的可靠性，打开ADO连接时，可以加入异常处理代码。 <BR>try{ <BR>m_pDBConn-&gt;Open("","","",NULL); <BR>}catch(_com_error &amp;e){ <BR>//处理异常的代码 <BR>. . . . . . . . . . . . . . . . . . . . . . . . . . . . .&nbsp; <BR>m_pDBConn=NULL; <BR>} <BR>因为_ConnectionPtr m_pDBConn是智能指针，应在处理异常代码时将智能指针设为NULL后将自动将引用计数降为0。 <BR>如果不出现异常，只要在使用完m_pDBConn，只要引用Close方法即可。 <BR>2.创建你所需的UDL文件 <BR>在你所想创建UDL文件的目录中单击右键，选择从菜单 新建|Microsoft 数据连接，然后将新创建的UDL文件更改为你所希望的文件名（.UDL扩展名不能改变）。 <BR>注：如果操作系统是Window 2000，先创建一个文本文件，再将该文本文件的扩展名改为 "udl"。 <BR>然后双击所创建的UDL文件，即可视化地完成数据源的设定。 <BR>使用UDL文件必须在系统中先安装Microsoft MDAC，Win 98第二版，Win 2000中都自动包含了该组件，需要该组件最新版本时可以到Microsoft网站去下载。 </FONT></P>]]></description>
</item><item>
<title><![CDATA[[转载]VC++ ADO开发实践之二]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=fishyqd&amp;id=13043</link>
<author>fishyqd</author>
<pubDate>2006/3/30 21:17:32</pubDate>
<description><![CDATA[<P><FONT size=2>日期：2005-06-06 人气：
<SCRIPT language=javascript src="../Read.php?ID=5671d260"></SCRIPT>
 88 出处：<A href="http://www.csdn.net/" target=_blank><SPAN class=px12>CSDN</SPAN></A> 作者: zswzwy <BR></FONT></P>
<P><FONT size=2>一、前言<BR>在上一篇文章《ADO第一次亲密接触》中我们详细介绍了ADO基本的操作方法，在实际的开发过程中我们常常需要存储较大的二进制数据对象，比如：图像、音频文件、或其它二进制数据，这些数据我们称之为二进制大对象BLOB(Binary Large Object),其存取的方式与普通数据有所区别。本文将介绍利用ADO在数据库中存取BLOB数据的具体实现过程，并给出实现图像存取显示的完整示例工程。</FONT></P>
<P><BR><FONT size=2>二、前期准备<BR>首先我们建立一张名为userinfo的表，包含三个字段:id,username,old,photo,其中photo是一个可以存储二进制数据的字段。<BR>2.1 在SQL SERVER中我们可以在Query Analyzer中直接输入如下语句创建：</FONT></P>
<P><BR><FONT size=2>CREATE TABLE [dbo].[userphoto] (<BR>&nbsp;[id] [int] IDENTITY (1, 1) NOT NULL ,<BR>&nbsp;[username] [varchar] (50) NULL ,<BR>&nbsp;[old] [int] NULL ,<BR>&nbsp;[photo] [image] NULL <BR>) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]<BR>其中photo我们定义为image类型的字段。</FONT></P>
<P><BR><FONT size=2>2.2 在ACCESS中创建的方法如下：<BR>建立一张新表包括id,username,old,photo四个字段，然后打开表，选视图菜单中设计视图，将id设置为自动编号的递增长整型，username为文本，old为数字，photo为OLE对象。<BR>在我们的示例工程中已经包含了一个建立好的ACCESS2000的库，你可以直接拿来使用。</FONT></P>
<P><BR><FONT size=2>三、具体步骤<BR>3.1 BLOB数据的保存<BR>BLOB类型的数据无法用普通的方式进行存储，我们需要使用AppendChunk函数，AppendChunk包含在Field对象中，原型如下：<BR>HRESULT AppendChunk (const _variant_t &amp; Data );<BR>从函数原型中可以看到关键的问题是我们需把二进制数据赋值给VARIANT类型的变量，下面我们给出具体的代码并作简单的分析:</FONT></P>
<P><FONT size=2></FONT>&nbsp;</P>
<P><FONT size=2><BR>///假设m_pBMPBuffer指针指向一块长度为m_nFileLen的二进制数据,并且已经成功打开了记录集对象m_pRecordset///</FONT></P>
<P><FONT size=2>char&nbsp;&nbsp;*pBuf = m_pBMPBuffer;<BR>VARIANT&nbsp;&nbsp;varBLOB;<BR>SAFEARRAY&nbsp;*psa;<BR>SAFEARRAYBOUND&nbsp;rgsabound[1];</FONT></P>
<P><FONT size=2>m_pRecordset-&gt;AddNew();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ///添加新记录<BR>m_pRecordset-&gt;PutCollect("username",_variant_t("小李"));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ///为新记录填充username字段<BR>m_pRecordset-&gt;PutCollect("old",_variant_t((long)28);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ///填充old字段<BR>if(pBuf)<BR>{&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp; rgsabound[0].lLbound = 0;<BR>&nbsp;&nbsp; rgsabound[0].cElements = m_nFileLen;<BR>&nbsp;&nbsp; psa = SafeArrayCreate(VT_UI1, 1, rgsabound);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ///创建SAFEARRAY对象<BR>&nbsp;&nbsp; for (long i = 0; i &lt; (long)m_nFileLen; i++)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SafeArrayPutElement (psa, &amp;i, pBuf++);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ///将pBuf指向的二进制数据保存到SAFEARRAY对象psa中<BR>&nbsp;&nbsp; varBLOB.vt = VT_ARRAY | VT_UI1;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ///将varBLOB的类型设置为BYTE类型的数组<BR>&nbsp;&nbsp; varBLOB.parray = psa;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ///为varBLOB变量赋值<BR>&nbsp;&nbsp; m_pRecordset-&gt;GetFields()-&gt;GetItem("photo")-&gt;AppendChunk(varBLOB);///加入BLOB类型的数据<BR>} <BR>m_pRecordset-&gt;Update();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ///保存我们的数据到库中<BR>至此我们的数据已经成功地保存到了数据库中,接下来我们所要做的工作便是将该数据提取出来,让我们继续吧!</FONT></P>
<P><FONT size=2>3.2 BLOB数据的读取<BR>对应于保存数据时我们所使用的AppendChunk函数，读取数据应该使用GetChunk函数,GetChunk的原型如下:<BR>_variant_t GetChunk (long Length );<BR>给出数据的长度后GetChunk将返回包含数据的VARIANT类型变量,然后我们可以利用SafeArrayAccessData函数得到VARIANT变量中指向数据的char *类型的指针,以方便我们的处理，具体代码如下：</FONT></P>
<P><FONT size=2></FONT>&nbsp;</P>
<P><FONT size=2>long lDataSize = m_pRecordset-&gt;GetFields()-&gt;GetItem("photo")-&gt;ActualSize;///得到数据的长度<BR>if(lDataSize &gt; 0)<BR>{<BR>&nbsp;&nbsp; _variant_t varBLOB;<BR>&nbsp;&nbsp; varBLOB = m_pRecordset-&gt;GetFields()-&gt;GetItem("photo")-&gt;GetChunk(lDataSize);<BR>&nbsp;&nbsp; if(varBLOB.vt == (VT_ARRAY | VT_UI1))&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ///判断数据类型是否正确<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char *pBuf = NULL;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SafeArrayAccessData(varBLOB.parray,(void **)&amp;pBuf);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ///得到指向数据的指针<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /*****在这里我们可以对pBuf中的数据进行处理*****/<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SafeArrayUnaccessData (varBLOB.parray);<BR>&nbsp;&nbsp; }<BR>}<BR>以上我们成功实现了BLOB数据在数据库中的存取，为了让大家有现成的例子可以参考，本文提供了示例工程，在示例工程中我们在数据库中保存图像数据，并可以对这些图像进行浏览、修改，该例子还涉及到如何用char *指向的BMP文件数据创建BITMAP对象然后显示出来。</FONT></P>]]></description>
</item><item>
<title><![CDATA[[转载]VC++ ADO开发实践之一]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=fishyqd&amp;id=13042</link>
<author>fishyqd</author>
<pubDate>2006/3/30 21:15:54</pubDate>
<description><![CDATA[<TABLE style="TABLE-LAYOUT: fixed; BORDER-COLLAPSE: collapse" cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD class=article_title align=middle height=30><B>VC++ ADO开发实践之一</B></TD></TR>
<TR>
<TD align=middle width="100%" bgColor=#888888 height=1></TD></TR>
<TR>
<TD width="100%" height=2></TD></TR>
<TR>
<TD width="100%" height=38>
<P align=center><B>作者</B>：未知 <B>来源</B>：月光软件站<!--未知--> <B>加入时间</B>：2005-2-28　月光软件站</P></TD></TR>
<TR>
<TD vAlign=top width="100%">
<P><FONT size=2>ADO第一次亲密接触 -- ADO开发实践之一<BR>&nbsp;<BR>一、ADO简介<BR>ADO(ActiveX Data Object)是Microsoft数据库应用程序开发的新接口，是建立在OLE DB之上的高层数据库访问技术，请不必为此担心，即使你对OLE DB，COM不了解也能轻松对付ADO,因为它非常简单易用，甚至比你以往所接触的ODBC API、DAO、RDO都要容易使用，并不失灵活性。本文将详细地介绍在VC下如何使用ADO来进行数据库应用程序开发，并给出示例代码。<BR>本文示例代码 </FONT></P>
<P><FONT size=2>二、基本流程<BR>万事开头难，任何一种新技术对于初学者来说最重要的还是“入门”，掌握其要点。让我们来看看ADO数据库开发的基本流程吧！<BR>(1)初始化COM库，引入ADO库定义文件<BR>(2)用Connection对象连接数据库<BR>(3)利用建立好的连接，通过Connection、Command对象执行SQL命令，或利用Recordset对象取得结果记录集进行查询、处理。<BR>(4)使用完毕后关闭连接释放对象。</FONT></P>
<P><FONT size=2>准备工作:<BR>为了大家都能测试本文提供的例子，我们采用Access数据库，您也可以直接在我们提供的示例代码中找到这个test.mdb。<BR>下面我们将详细介绍上述步骤并给出相关代码。<BR>【1】COM库的初始化<BR>我们可以使用AfxOleInit()来初始化COM库，这项工作通常在CWinApp::InitInstance()的重载函数中完成，请看如下代码:</FONT></P>
<P><BR><FONT size=2>BOOL CADOTest1App::InitInstance()<BR>&nbsp; {<BR>&nbsp; AfxOleInit();<BR>&nbsp; ...... </FONT></P>
<P><FONT size=2>【2】用#import指令引入ADO类型库<BR>我们在stdafx.h中加入如下语句：(stdafx.h这个文件哪里可以找到?你可以在FileView中的Header Files里找到)</FONT></P>
<P><FONT size=2>#import "c:\program files\common files\system\ado\msado15.dll" no_namespace rename("EOF","adoEOF")<BR>这一语句有何作用呢？其最终作用同我们熟悉的#include类似,编译的时候系统会为我们生成msado15.tlh,ado15.tli两个C++头文件来定义ADO库。</FONT></P>
<P><FONT size=2>几点说明:<BR>(1) 您的环境中msado15.dll不一定在这个目录下，请按实际情况修改<BR>(2) 在编译的时候肯能会出现如下警告，对此微软在MSDN中作了说明，并建议我们不要理会这个警告。<BR>msado15.tlh(405) : warning C4146: unary minus operator applied to unsigned type, result still unsigned </FONT></P>
<P><FONT size=2>【3】创建Connection对象并连接数据库<BR>首先我们需要添加一个指向Connection对象的指针:<BR>_ConnectionPtr m_pConnection;<BR>下面的代码演示了如何创建Connection对象实例及如何连接数据库并进行异常捕捉。</FONT></P>
<P><BR><FONT size=2>BOOL CADOTest1Dlg::OnInitDialog()<BR>&nbsp; {<BR>&nbsp; CDialog::OnInitDialog();<BR>&nbsp; HRESULT hr;<BR>&nbsp; try<BR>&nbsp; {<BR>&nbsp; hr = m_pConnection.CreateInstance("ADODB.Connection");///创建Connection对象<BR>&nbsp; if(SUCCEEDED(hr))<BR>&nbsp; {<BR>&nbsp; hr = m_pConnection-&gt;Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=test.mdb","","",adModeUnknown);///连接数据库<BR>&nbsp; ///上面一句中连接字串中的Provider是针对ACCESS2000环境的，对于ACCESS97,需要改为:Provider=Microsoft.Jet.OLEDB.3.51;<BR>&nbsp; }<BR>&nbsp; }<BR>&nbsp; catch(_com_error e)///捕捉异常<BR>&nbsp; {<BR>&nbsp; CString errormessage;<BR>&nbsp; errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage());<BR>&nbsp; AfxMessageBox(errormessage);///显示错误信息<BR>&nbsp; } </FONT></P>
<P><FONT size=2>在这段代码中我们是通过Connection对象的Open方法来进行连接数据库的，下面是该方法的原型<BR>HRESULT Connection15::Open ( _bstr_t ConnectionString, _bstr_t UserID, _bstr_t Password, long Options )<BR>ConnectionString为连接字串,UserID是用户名, Password是登陆密码,Options是连接选项,用于指定Connection对象对数据的更新许可权,<BR>Options可以是如下几个常量:<BR>adModeUnknown:缺省。当前的许可权未设置<BR>adModeRead:只读<BR>adModeWrite:只写<BR>adModeReadWrite:可以读写<BR>adModeShareDenyRead:阻止其它Connection对象以读权限打开连接<BR>adModeShareDenyWrite:阻止其它Connection对象以写权限打开连接<BR>adModeShareExclusive:阻止其它Connection对象以读写权限打开连接<BR>adModeShareDenyNone:阻止其它Connection对象以任何权限打开连接</FONT></P>
<P><FONT size=2>我们给出一些常用的连接方式供大家参考:<BR>(1)通过JET数据库引擎对ACCESS2000数据库的连接</FONT></P>
<P><FONT size=2>m_pConnection-&gt;Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\test.mdb","","",adModeUnknown);</FONT></P>
<P><FONT size=2>(2)通过DSN数据源对任何支持ODBC的数据库进行连接:</FONT></P>
<P><FONT size=2>m_pConnection-&gt;Open("Data Source=adotest;UID=sa;PWD=;","","",adModeUnknown);</FONT></P>
<P><FONT size=2>(3)不通过DSN对SQL SERVER数据库进行连接： <BR>m_pConnection-&gt;Open("driver={SQL Server};Server=127.0.0.1;DATABASE=vckbase;UID=sa;PWD=139","","",adModeUnknown);</FONT></P>
<P><FONT size=2>其中Server是SQL服务器的名称，DATABASE是库的名称</FONT></P>
<P><FONT size=2>Connection对象除Open方法外还有许多方法，我们先介绍Connection对象中两个有用的属性ConnectionTimeOut与State<BR>ConnectionTimeOut用来设置连接的超时时间，需要在Open之前调用，例如: <BR>m_pConnection-&gt;ConnectionTimeout = 5;///设置超时时间为5秒<BR>m_pConnection-&gt;Open("Data Source=adotest;","","",adModeUnknown);</FONT></P>
<P><BR><FONT size=2>State属性指明当前Connection对象的状态，0表示关闭，1表示已经打开，我们可以通过读取这个属性来作相应的处理，例如:</FONT></P>
<P><FONT size=2>if(m_pConnection-&gt;State)<BR>&nbsp;&nbsp;&nbsp;&nbsp; m_pConnection-&gt;Close(); ///如果已经打开了连接则关闭它</FONT></P>
<P><BR><FONT size=2>【4】执行SQL命令并取得结果记录集<BR>为了取得结果记录集，我们定义一个指向Recordset对象的指针:_RecordsetPtr m_pRecordset;<BR>并为其创建Recordset对象的实例: m_pRecordset.CreateInstance("ADODB.Recordset");<BR>SQL命令的执行可以采用多种形式，下面我们一进行阐述。</FONT></P>
<P><FONT size=2>(1)利用Connection对象的Execute方法执行SQL命令<BR>Execute方法的原型如下所示:<BR>_RecordsetPtr Connection15::Execute ( _bstr_t CommandText, VARIANT * RecordsAffected, long Options ) 其中CommandText是命令字串，通常是SQL命令。参数RecordsAffected是操作完成后所影响的行数, 参数Options表示CommandText中内容的类型，Options可以取如下值之一：<BR>adCmdText:表明CommandText是文本命令<BR>adCmdTable:表明CommandText是一个表名<BR>adCmdProc:表明CommandText是一个存储过程<BR>adCmdUnknown:未知</FONT></P>
<P><FONT size=2>Execute执行完后返回一个指向记录集的指针，下面我们给出具体代码并作说明。 <BR>&nbsp; _variant_t RecordsAffected;<BR>&nbsp; ///执行SQL命令：CREATE TABLE创建表格users,users包含四个字段:整形ID,字符串username,整形old,日期型birthday<BR>&nbsp; m_pConnection-&gt;Execute("CREATE TABLE users(ID INTEGER,username TEXT,old INTEGER,birthday DATETIME)",&amp;RecordsAffected,adCmdText);<BR>&nbsp; ///往表格里面添加记录<BR>&nbsp; m_pConnection-&gt;Execute("INSERT INTO users(ID,username,old,birthday) VALUES (1, 'Washington',25,'1970/1/1')",&amp;RecordsAffected,adCmdText);<BR>&nbsp; ///将所有记录old字段的值加一<BR>&nbsp; m_pConnection-&gt;Execute("UPDATE users SET old = old+1",&amp;RecordsAffected,adCmdText);<BR>&nbsp; ///执行SQL统计命令得到包含记录条数的记录集<BR>&nbsp; m_pRecordset =&nbsp; m_pConnection-&gt;Execute("SELECT COUNT(*) FROM users",&amp;RecordsAffected,adCmdText);<BR>&nbsp; _variant_t vIndex = (long)0;<BR>&nbsp; _variant_t vCount = m_pRecordset-&gt;GetCollect(vIndex);///取得第一个字段的值放入vCount变量<BR>&nbsp; m_pRecordset-&gt;Close();///关闭记录集<BR>&nbsp; CString message;<BR>&nbsp; message.Format("共有%d条记录",vCount.lVal);<BR>&nbsp; AfxMessageBox(message);///显示当前记录条数</FONT></P>
<P><BR><FONT size=2>(2)利用Command对象来执行SQL命令</FONT></P>
<P><FONT size=2>&nbsp; _CommandPtr m_pCommand;<BR>&nbsp; m_pCommand.CreateInstance("ADODB.Command");<BR>&nbsp; _variant_t vNULL;<BR>&nbsp; vNULL.vt = VT_ERROR;<BR>&nbsp; vNULL.scode = DISP_E_PARAMNOTFOUND;///定义为无参数<BR>&nbsp; m_pCommand-&gt;ActiveConnection = m_pConnection;///非常关键的一句，将建立的连接赋值给它<BR>&nbsp; m_pCommand-&gt;CommandText = "SELECT * FROM users";///命令字串<BR>&nbsp; m_pRecordset = m_pCommand-&gt;Execute(&amp;vNULL,&amp;vNULL,adCmdText);///执行命令，取得记录集</FONT></P>
<P><FONT size=2>在这段代码中我们只是用Command对象来执行了SELECT查询语句，Command对象在进行存储过程的调用中能真正体现它的作用。下次我们将详细介绍。 </FONT></P>
<P><BR><FONT size=2>(3)直接用Recordset对象进行查询取得记录集 <BR>例如 </FONT></P>
<P><FONT size=2>&nbsp; m_pRecordset-&gt;Open("SELECT * FROM users",_variant_t((IDispatch *)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);</FONT></P>
<P><FONT size=2>Open方法的原型是这样的:<BR>HRESULT Recordset15::Open ( const _variant_t &amp; Source, const _variant_t &amp; ActiveConnection, enum CursorTypeEnum CursorType, enum LockTypeEnum LockType, long Options ) <BR>其中：<BR>①Source是数据查询字符串<BR>②ActiveConnection是已经建立好的连接（我们需要用Connection对象指针来构造一个_variant_t对象) <BR>③CursorType光标类型，它可以是以下值之一,请看这个枚举结构:<BR>enum CursorTypeEnum<BR>{<BR>adOpenUnspecified = -1,///不作特别指定<BR>adOpenForwardOnly = 0,///前滚静态光标。这种光标只能向前浏览记录集，比如用MoveNext向前滚动,这种方式可以提高浏览速度。但诸如BookMark,RecordCount,AbsolutePosition,AbsolutePage都不能使用<BR>adOpenKeyset = 1,///采用这种光标的记录集看不到其它用户的新增、删除操作，但对于更新原有记录的操作对你是可见的。<BR>adOpenDynamic = 2,///动态光标。所有数据库的操作都会立即在各用户记录集上反应出来。<BR>adOpenStatic = 3///静态光标。它为你的记录集产生一个静态备份，但其它用户的新增、删除、更新操作对你的记录集来说是不可见的。<BR>};<BR>④LockType锁定类型，它可以是以下值之一，请看如下枚举结构：<BR>enum LockTypeEnum<BR>{<BR>adLockUnspecified = -1,///未指定<BR>adLockReadOnly = 1,///只读记录集<BR>adLockPessimistic = 2,悲观锁定方式。数据在更新时锁定其它所有动作，这是最安全的锁定机制<BR>adLockOptimistic = 3,乐观锁定方式。只有在你调用Update方法时才锁定记录。在此之前仍然可以做数据的更新、插入、删除等动作<BR>adLockBatchOptimistic = 4，乐观分批更新。编辑时记录不会锁定，更改、插入及删除是在批处理模式下完成。<BR>}; <BR>⑤Options请参考本文中对Connection对象的Execute方法的介绍</FONT></P>
<P><FONT size=2></FONT>&nbsp;</P>
<P><FONT size=2>【5】记录集的遍历、更新<BR>根据我们刚才通过执行SQL命令建立好的users表，它包含四个字段:ID,username,old,birthday<BR>以下的代码实现：打开记录集，遍历所有记录，删除第一条记录，添加三条记录，移动光标到第二条记录，更改其年龄，保存到数据库。</FONT></P>
<P><BR><FONT size=2>_variant_t vUsername,vBirthday,vID,vOld;<BR>_RecordsetPtr m_pRecordset;<BR>m_pRecordset.CreateInstance("ADODB.Recordset");<BR>m_pRecordset-&gt;Open("SELECT * FROM users",_variant_t((IDispatch*)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);<BR>while(!m_pRecordset-&gt;adoEOF)///这里为什么是adoEOF而不是EOF呢?还记得rename("EOF","adoEOF")这一句吗?<BR>{<BR>&nbsp;vID = m_pRecordset-&gt;GetCollect(_variant_t((long)0));///取得第1列的值,从0开始计数，你也可以直接给出列的名称，如下一行<BR>&nbsp;vUsername = m_pRecordset-&gt;GetCollect("username");///取得username字段的值<BR>&nbsp;vOld = m_pRecordset-&gt;GetCollect("old");<BR>&nbsp;vBirthday = m_pRecordset-&gt;GetCollect("birthday");<BR>&nbsp;///在DEBUG方式下的OUTPUT窗口输出记录集中的记录<BR>&nbsp;if(vID.vt != VT_NULL &amp;&amp; vUsername.vt != VT_NULL &amp;&amp; vOld.vt != VT_NULL &amp;&amp; vBirthday.vt != VT_NULL)<BR>&nbsp;&nbsp;TRACE("id:%d,姓名:%s,年龄:%d,生日:%s\r\n",vID.lVal,(LPCTSTR)(_bstr_t)vUsername,vOld.lVal,(LPCTSTR)(_bstr_t)vBirthday);<BR>&nbsp;m_pRecordset-&gt;MoveNext();///移到下一条记录<BR>}<BR>m_pRecordset-&gt;MoveFirst();///移到首条记录<BR>m_pRecordset-&gt;Delete(adAffectCurrent);///删除当前记录<BR>///添加三条新记录并赋值<BR>for(int i=0;i&lt;3;i++)<BR>{<BR>&nbsp;m_pRecordset-&gt;AddNew();///添加新记录<BR>&nbsp;m_pRecordset-&gt;PutCollect("ID",_variant_t((long)(i+10)));<BR>&nbsp;m_pRecordset-&gt;PutCollect("username",_variant_t("叶利钦"));<BR>&nbsp;m_pRecordset-&gt;PutCollect("old",_variant_t((long)71));<BR>&nbsp;m_pRecordset-&gt;PutCollect("birthday",_variant_t("1930-3-15"));<BR>}<BR>m_pRecordset-&gt;Move(1,_variant_t((long)adBookmarkFirst));///从第一条记录往下移动一条记录,即移动到第二条记录处<BR>m_pRecordset-&gt;PutCollect(_variant_t("old"),_variant_t((long)45));///修改其年龄<BR>m_pRecordset-&gt;Update();///保存到库中</FONT></P>
<P><FONT size=2>【6】关闭记录集与连接 <BR>记录集或连接都可以用Close方法来关闭 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_pRecordset-&gt;Close();///关闭记录集<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_pConnection-&gt;Close();///关闭连接</FONT></P>
<P><FONT size=2>后记：限于篇幅ADO中的许多内容还没有介绍，下次我们将详细介绍Recordset对象的属性、方法并解决几个关键的技术：绑定方式处理记录集数据、存储过程的调用、事务处理、图象在数据库中的保存与读取、与表格控件的配合使用等。 <BR>下次再见吧!&nbsp; </FONT></P></TD></TR></TBODY></TABLE>]]></description>
</item><item>
<title><![CDATA[VC++ ADO连接SQL Server问题与解决方案]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=fishyqd&amp;id=13038</link>
<author>fishyqd</author>
<pubDate>2006/3/30 16:30:45</pubDate>
<description><![CDATA[<P>以前没有用VC连接过数据库，今天由于帮人做毕设就尝试了一下。</P>
<P>(1)建立ODBC数据源。</P>
<P>参考方法：<A href="http://www.gz9f.com/jiaocai/hcc/hcc6/hcc6-p1/hcc6-p1.htm">http://www.gz9f.com/jiaocai/hcc/hcc6/hcc6-p1/hcc6-p1.htm</A></P>
<P>牢记：在此之前要把自己的数据库服务器启动，不然在服务器选择的时候看不到自己的服务器。</P>
<P>（2）</P>
<P>&nbsp;&nbsp; 在工程的stdafx.h里用#import引入ADO库文件。<BR>　　<BR>　　#import "C:\Program Files\Common Files\System\ado\msado15.dll"　no_namespace　rename("BOF","adoBOF") rename("EOF","adoEOF")</P>
<P>&nbsp;&nbsp; 牢记：一定要在所有的#include后加入这句话，不然会出现。<SPAN lang=EN-US><STRONG><FONT face="Times New Roman">fatal error C1189: #error :<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>WINDOWS.H already included.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>MFC apps must not #：nclude &lt;windows.h&gt;</FONT></STRONG></SPAN></P>
<P><SPAN lang=EN-US>我是参考了如下文章：<A href="http://www.allife.org/index.php?job=art&amp;articleid=a_20060116_134912">http://www.allife.org/index.php?job=art&amp;articleid=a_20060116_134912</A></SPAN></P>
<P><SPAN lang=EN-US>原文引用如下：</SPAN></P><SPAN lang=EN-US>
<DIV class=entrybor>
<DIV class=title>非MFC工程使用MFC库时的问题及解决办法</DIV></DIV>
<P><SPAN class=date>2006年1月16日13:49星期一&nbsp;&nbsp;[<A href="http://www.allife.org/index.php?job=showcat&amp;cat=2"><FONT color=#666666>笔记</FONT></A>]</SPAN> 
<TABLE cellSpacing=0 cellPadding=0 width="98%" border=0>
<TBODY>
<TR>
<TD class=entrycontent vAlign=top><SPAN id=zoom>
<P class=MsoNormal style="MARGIN: 0pt"><B><SPAN style="COLOR: purple; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>文章来源:</FONT><A class=headermaintitle id=Header1_HeaderTitle href="http://blog.csdn.net/sunshine1314/"><FONT color=#666666 size=2>李世平的专栏</FONT></A></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0pt"><B><SPAN style="COLOR: purple; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT color=#666666></FONT></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0pt"><B><SPAN style="COLOR: purple; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT color=#666666></FONT></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0pt"><B><SPAN style="COLOR: purple; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">一、问题由来</SPAN><SPAN lang=EN-US style="COLOR: purple"> </SPAN></B>
<P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US><FONT face="Times New Roman">vc6</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">vc71</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的工程向导中都包含非</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">MFC</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的工程，诸如</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">win32 console project, win32 static library</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。非</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">MFC</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">工程创建时是不支持</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">MFC</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">特性的，然后我们在处理实际问题时有时会用到</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">MFC</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">相关类，如</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">Cstring, Cedit</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">等等，这是很正常的。可能有人会说，为何不在一开始就创建</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">MFC</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">工程呢？问题在于</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">MFC</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">工程会产生很多向导生成代码，如基于单文档的工程会有</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">View,Doc</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">等类，很多时候我们只需要一个空工程就可以了。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US><FONT face="Times New Roman">&nbsp; </FONT></SPAN>
<P>
<P class=MsoNormal style="MARGIN: 0pt"><B><SPAN style="COLOR: purple; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">二、常见问题</SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">非</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">MFC</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">工程使用</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">MFC</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">库时最常见的问题就是</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">windows.h</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">重复包含错误，具体如下：</SPAN></P>
<P class=MsoBodyText style="MARGIN: 0pt"><SPAN lang=EN-US><STRONG><FONT face="Times New Roman">fatal error C1189: #error :<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>WINDOWS.H already included.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>MFC apps must not #include &lt;windows.h&gt;</FONT></STRONG></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US><FONT face="Times New Roman">&nbsp; </FONT></SPAN>
<P>
<P class=MsoNormal style="MARGIN: 0pt"><B><SPAN style="COLOR: purple; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">三、解决办法</SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">非</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">MFC</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">工程使用</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">MFC</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">库时，可参考以下步骤</SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US><FONT face="Times New Roman">1</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、工程设置中，将</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">MFC</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的使用由原来的“使用标准</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">windows</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">库”改为“在共享</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">DLL</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中使用</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">MFC</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">”（</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">VC71</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）</SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">如果是英文版，相关选项是：</SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US><FONT face="Times New Roman">Microsoft Foundation Classes: Use MFC in a shared dll, no using MFC</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">（</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">VC6</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）</SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US><FONT face="Times New Roman">NOTE:</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">因为我用的是中文版的</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">vc71,</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">英文版的</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">vc6.</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US><FONT face="Times New Roman">2</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、头文件包含</SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">不同的</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">MFC</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">类需包含的头文件是不一样的。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">常用的类，如</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">Cstring, Cedit </FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">等，包含</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">afxwin.h</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">就可以了</SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">如果不清楚包含什么头文件的话，可以同</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">msdn</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">进行查询，</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">msdn</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中，对于</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">MFC</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">类的介绍中，都会给出相应的</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">header file requirement.</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US><FONT face="Times New Roman">3</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、＃</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">include </FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">语句一定要写在首行</SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这一点很重要，通常出现前面讲到的</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">windows.h</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">重复包含错误，都是因为</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">#include </FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">语句没有写在首行。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">另外还要注意的是，如果</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">#include</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">语句是在一个头文件里，那么对应头文件的包含也要写在首行。示例如下：</SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">＝＝＝＝＝＝＝＝＝＝＝＝＝</SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US><FONT face="Times New Roman">test.h</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">文件的内容如下：</SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">＃</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">include &lt;afxwin.h&gt; //</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">保证该语句在首行</SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US><FONT face="Times New Roman">test.cpp</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的文件内容如下：</SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US><FONT face="Times New Roman">#include “test.h” //</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">同样也要保证该语句在首行</SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">＝＝＝＝＝＝＝＝＝＝＝＝＝</SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US><FONT face="Times New Roman">ps: </FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这么做的具体原因我也不知道，我是在实际调试中琢磨出这个道理的。我自己在这个问题上花了很多冤枉时间，写下该篇，就是希望大家不要在这个问题上绊脚。</SPAN></P>
<P></P>
<P></P>
<P></P>
<P>（3）在进行连接之前要初始化OLE环境，初始化语句</P>
<P>&nbsp;&nbsp; ::CoInitialize(NULL); //初始化OLE/COM库环境　<BR>　　<BR>　　AfxOleInit();//初始化OLE/COM库环境(MFC自带的)</P>
<P>&nbsp;&nbsp;&nbsp; 这两句话缺一不可，不然会有运行期错误</P>
<P>&nbsp;&nbsp;&nbsp; 程序运行结束后记住::CoUninitialize();　 //关闭OLE/COM库环境，释放资源</P>
<P>最后推荐一篇文章：<A href="http://farwen.com/ReadNews.asp?NewsID=3279">http://farwen.com/ReadNews.asp?NewsID=3279</A></P>
<P>全文引用如下：</P>
<P>
<TABLE style="TABLE-LAYOUT: fixed" cellSpacing=0 cellPadding=0 width="90%" align=center border=0>
<TBODY>
<TR>
<TD style="FONT-SIZE: 18px" vAlign=bottom align=middle width="100%" height=40><FONT color=#000066><B>ADO数据库编程入门<BR></B></FONT></TD></TR>
<TR>
<TD align=middle width="100%">
<HR align=center width="100%" noShade SIZE=1>
</TD></TR>
<TR>
<TD style="FONT-SIZE: 9pt" align=middle width="100%">2004-11-16 19:55:41&nbsp;&nbsp;天宇网苑&nbsp;&nbsp;Keaton&nbsp;&nbsp;阅读301次</TD></TR>
<TR>
<TD style="LEFT: 0px; WIDTH: 100%; WORD-WRAP: break-word"><BR><FONT class=news>
<P>1、使用ADO编程的方法有三种：<BR>（1）使用预处理指令#import，例如：<BR>#import "c:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF", "adoEOF") rename("BOF", "adoBOF")<BR>程序在编译时读取msado15.dll中的类型库信息，自动生成两个该类型库的头文件和实现文件msado15.tlh和msado15.tli（在Debug或Release目录下）。两个文件中定义了ADO的所有对象和方法，以及一些枚举类型的变量，程序只要直接调用这些方法即可。<BR>（2）通过读取msado15.dll中的类型库信息，建立一个ColeDispatchDriver类的派生类，然后通过它调用ADO对象。<BR>（3）直接使用COM提供的API，例如：<BR>&nbsp;CLSID clsid;<BR>&nbsp;HRESULT hr = ::CLSIDFromProgID(L"ADODB.Connection", &amp;clsid);<BR>&nbsp;if (FAILED(hr))<BR>&nbsp;{<BR>&nbsp;&nbsp;...<BR>&nbsp;}<BR>&nbsp;::CoCreateInstance(clsid, NULL, CLSCTX_SERVER, IID_IDispatch, (void **)&amp;pDispatch);<BR>&nbsp;if (FAILED(hr))<BR>&nbsp;{<BR>&nbsp;&nbsp;...<BR>&nbsp;}<BR>前两种方法类似，第3种方法编程可能最麻烦，但效率最高，程序尺寸最小，并且对ADO的控制能力也最强。<BR>2、以下使用#import方法操作数据库<BR>（1）可以在stdafx.h的所有include指令之后import<BR>（2）使用AfxOleInit()初始化COM库，通常在CwinApp::InitInstance的重载函数中添加。<BR>（也可以使用::CoInitialize(NULL)，之后在ExitInstance中调用::CoUninitialize）<BR>（3）定义_ConnectionPtr变量后调用Connection对象的Open方法建立与服务器的连接。<BR>数据类型_ConnectionPtr实际上是由类模板_com_ptr_t得到的一个具体的实例类。_ConnectionPtr类封装了Connection对象的Idispatch接口指针及其一些必要的操作。可以通过这个指针操纵Connection对象。<BR>例如连接SQLServer数据库，代码如下：<BR>&nbsp;// 连接到MS SQL Server<BR>&nbsp;_ConnectionPtr pMyConnect = NULL;<BR>&nbsp;HRESULT hr = pMyConnect.CreateInstance(__uuidof(Connection));<BR>&nbsp;if (FAILED(hr))<BR>&nbsp;&nbsp;return;</P>
<P>&nbsp;_bstr_t strConnect = "Provider=SQLOLEDB; Server=hch; Database=mytest; uid=sa; pwd=sa;";</P>
<P>&nbsp;try<BR>&nbsp;{<BR>&nbsp;&nbsp;// Open方法连接字串必须四BSTR或者_bstr_t类型<BR>&nbsp;&nbsp;pMyConnect-&gt;Open(strConnect, "", "", NULL);<BR>&nbsp;}<BR>&nbsp;catch(_com_error &amp;e)<BR>&nbsp;{<BR>&nbsp;&nbsp;MessageBox(e.Description(), "警告", MB_OK|MB_ICONINFORMATION);<BR>&nbsp;}<BR>（4）<BR>&nbsp;//定义_RecordsetPtr变量，调用它Recordset对象的Open，即可打开一个数据集<BR>&nbsp;_RecordsetPtr pRecordset;<BR>&nbsp;if (FAILED(pRecordset.CreateInstance(__uuidof(Recordset))))<BR>&nbsp;{<BR>&nbsp;&nbsp;return;<BR>&nbsp;}<BR>&nbsp;try<BR>&nbsp;{<BR>&nbsp;&nbsp;pRecordset-&gt;Open(_variant_t("userinfo"), _variant_t((IDispatch*)pMyConnect),<BR>&nbsp;&nbsp;&nbsp;adOpenKeyset, adLockOptimistic, adCmdTable);<BR>&nbsp;}<BR>&nbsp;catch (_com_error &amp;e) <BR>&nbsp;{<BR>&nbsp;&nbsp;MessageBox("无法打开userinfo表", "系统提示", MB_OK|MB_ICONINFORMATION);<BR>&nbsp;}<BR>（5）<BR>&nbsp;//定义_RecordsetPtr变量，调用它Recordset对象的Open，即可打开一个数据集<BR>&nbsp;_RecordsetPtr pRecordset;<BR>&nbsp;if (FAILED(pRecordset.CreateInstance(__uuidof(Recordset))))<BR>&nbsp;{<BR>&nbsp;&nbsp;return;<BR>&nbsp;}<BR>&nbsp;try<BR>&nbsp;{<BR>&nbsp;&nbsp;pRecordset-&gt;Open(_variant_t("userinfo"), _variant_t((IDispatch*)pMyConnect),<BR>&nbsp;&nbsp;&nbsp;adOpenKeyset, adLockOptimistic, adCmdTable);<BR>&nbsp;}<BR>&nbsp;catch (_com_error &amp;e) <BR>&nbsp;{<BR>&nbsp;&nbsp;MessageBox("无法打开userinfo表", "系统提示", MB_OK|MB_ICONINFORMATION);<BR>&nbsp;}<BR>（6）<BR>&nbsp;// 读取当前记录集<BR>&nbsp;try<BR>&nbsp;{<BR>&nbsp;&nbsp;pRecordset-&gt;MoveFirst();<BR>&nbsp;&nbsp;while (pRecordset-&gt;adoEOF == VARIANT_FALSE)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;// Fields是Recordset对象的容器，GetItem方法返回Field对象，Value是Field对象的属性，也可以用GetValue方法<BR>&nbsp;&nbsp;&nbsp;CString sName = (char*)(_bstr_t)(pRecordset-&gt;Fields-&gt;GetItem(_variant_t("UserName"))-&gt;Value);<BR>&nbsp;&nbsp;&nbsp;// 或者使用GetValue()<BR>&nbsp;&nbsp;&nbsp;//CString sName = (char*)(_bstr_t)(pRecordset-&gt;Fields-&gt;GetItem(_variant_t("UserName"))-&gt;GetValue());<BR>&nbsp;&nbsp;&nbsp;AfxMessageBox(sName);<BR>&nbsp;&nbsp;&nbsp;pRecordset-&gt;MoveNext();<BR>&nbsp;&nbsp;}<BR>&nbsp;}<BR>&nbsp;catch (_com_error &amp;e) <BR>&nbsp;{<BR>&nbsp;&nbsp;MessageBox(e.Description(), "系统提示", MB_OK|MB_ICONINFORMATION);<BR>&nbsp;}<BR>（7）<BR>&nbsp;// 修改记录<BR>&nbsp;try<BR>&nbsp;{<BR>&nbsp;&nbsp;pRecordset-&gt;MoveFirst();<BR>&nbsp;&nbsp;while(pRecordset-&gt;adoEOF == VARIANT_FALSE)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;pRecordset-&gt;Fields-&gt;GetItem(_variant_t("Address"))-&gt;Value = _bstr_t("北京大学");<BR>&nbsp;&nbsp;&nbsp;pRecordset-&gt;Update();<BR>&nbsp;&nbsp;&nbsp;pRecordset-&gt;MoveNext();<BR>&nbsp;&nbsp;}<BR>&nbsp;}<BR>&nbsp;catch (_com_error &amp;e) <BR>&nbsp;{<BR>&nbsp;&nbsp;MessageBox(e.Description(), "系统提示", MB_OK|MB_ICONINFORMATION);<BR>&nbsp;}<BR>（8）添加，删除，使用带参数的命令，相应ADO的通知事件，绑定数据，设置过滤条件，索引和排序，事务处理。（略去，请参考其它资料）<BR></P></FONT></TD></TR>
<TR>
<TD width="100%" height=25>
<DIV align=right>
<P>&nbsp;</P></DIV></TD></TR>
<TR>
<TD width="100%">
<HR SIZE=1>
</TD></TR>
<TR>
<TD height=8></TD></TR>
<TR>
<TD width="100%" height=18><B>相关专题:</B><A class=lift href="http://farwen.com/Special_News.asp?SpecialID=5">原创文章</A></TD></TR>
<TR>
<TD width="100%" height=18><B>专题信息:</B></TD></TR>
<TR>
<TD height=8></TD></TR>
<TR>
<TD width="100%" height=18>&nbsp;<IMG src="http://farwen.com/images/go3.gif">&nbsp;<A class=middle href="http://farwen.com/ReadNews.asp?NewsID=3497" target=_top>Textarea中防止尖括号被替换</A><FONT color=#666666>(2004-12-30 16:29:17)[<FONT color=#ff0000>414</FONT>]</FONT></TD></TR>
<TR>
<TD width="100%" height=18>&nbsp;<IMG src="http://farwen.com/images/go3.gif">&nbsp;<A class=middle href="http://farwen.com/ReadNews.asp?NewsID=3439" target=_top>在视图(CEditView)中设置字体</A><FONT color=#666666>(2004-12-29 10:52:20)[<FONT color=#ff0000>324</FONT>]</FONT></TD></TR>
<TR>
<TD width="100%" height=18>&nbsp;<IMG src="http://farwen.com/images/go3.gif">&nbsp;<A class=middle href="http://farwen.com/ReadNews.asp?NewsID=3434" target=_top>随机产生23个4位数(每位数字不能重复)</A><FONT color=#666666>(2004-12-28 10:24:56)[<FONT color=#ff0000>266</FONT>]</FONT></TD></TR>
<TR>
<TD width="100%" height=18>&nbsp;<IMG src="http://farwen.com/images/go3.gif">&nbsp;<A class=middle href="http://farwen.com/ReadNews.asp?NewsID=3433" target=_top>输入密码不回显(显示*号)验证密码</A><FONT color=#666666>(2004-12-28 10:03:15)[<FONT color=#ff0000>433</FONT>]</FONT></TD></TR>
<TR>
<TD width="100%" height=18>&nbsp;<IMG src="http://farwen.com/images/go3.gif">&nbsp;<A class=middle href="http://farwen.com/ReadNews.asp?NewsID=3432" target=_top>cin输入字符串时的经典Bug</A><FONT color=#666666>(2004-12-27 15:01:48)[<FONT color=#ff0000>310</FONT>]</FONT></TD></TR>
<TR>
<TD align=right width="98%" height=18><A class=lift href="http://farwen.com/Special_News.asp?SpecialID=5">[更多... ]</A></TD></TR>
<TR>
<TD width="100%">
<HR SIZE=1>
</TD></TR>
<TR>
<TD height=8></TD></TR>
<TR>
<TD width="100%" height=18><B>相关信息:</B></TD></TR>
<TR>
<TD height=8></TD></TR>
<TR>
<TD width="100%">&nbsp;没有相关信息</TD></TR>
<TR>
<TD width="100%">
<HR SIZE=1>
</TD></TR>
<TR>
<TD height=8></TD></TR>
<TR>
<TD width="100%"><B>相关评论:</B></TD></TR>
<TR>
<TD height=8></TD></TR>
<TR>
<TD colSpan=2>
<TABLE cellSpacing=0 cellPadding=5 width="100%" border=0>
<TBODY>
<TR bgColor=#f0f0f0>
<TD colSpan=2>发表人：keaton</TD></TR>
<TR bgColor=#f0f0f0>
<TD colSpan=2>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD>发表人邮件：<A href="mailto:keaton@sohu.com">keaton@sohu.com</A></TD>
<TD align=right>发表时间：2005-5-9 13:47:13</TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD colSpan=2>
<TR>
<TD colSpan=2 height=20>下面让我们看看ADO数据库访问技术使用的基本步骤及方法：<BR>首先，要用#import语句来引用支持ADO的组件类型库(*.tlb)，其中类型库可以作为可执行程序(DLL、EXE等)的一部分被定位在其自身程序中的附属资源里，如：被定位在msado15.dll的附属资源中，只需要直接用#import引用它既可。可以直接在Stdafx.h文件中加入下面语句来实现： <BR><BR>#import "c:\program files\common files\system\ado\msado15.dll" \<BR>no_namespace \<BR>rename ("EOF", "adoEOF") <BR>其中路径名可以根据自己系统安装的ADO支持文件的路径来自行设定。当编译器遇到#import语句时，它会为引用组件类型库中的接口生成包装类，#import语句实际上相当于执行了API涵数LoadTypeLib()。#import语句会在工程可执行程序输出目录中产生两个文件，分别为*.tlh(类型库头文件)及*.tli(类型库实现文件)，它们分别为每一个接口产生智能指针，并为各种接口方法、枚举类型，CLSID等进行声明，创建一系列包装方法。语句no_namespace说明ADO对象不使用命名空间，rename ("EOF", "adoEOF")说明将ADO中结束标志EOF改为adoEOF，以避免和其它库中命名相冲突。<BR>其次，在程序初始过程中需要初始化组件，一般可以用CoInitialize(NULL);来实现，这种方法在结束时要关闭初始化的COM，可以用下面语句CoUnInitialize();来实现。在MFC中还可以采用另一种方法来实现初始化COM，这种方法只需要一条语句便可以自动为我们实现初始化COM和结束时关闭COM的操作，语句如下所示： AfxOleInit();<BR>接着，就可以直接使用ADO的操作了。我们经常使用的只是前面用#import语句引用类型库时，生成的包装类.tlh中声明的智能指针中的三个，它们分别是_ConnectionPtr、_RecordsetPtr和_CommandPtr。下面分别对它们的使用方法进行介绍：<BR>1、_ConnectionPtr智能指针，通常用于打开、关闭一个库连接或用它的Execute方法来执行一个不返回结果的命令语句(用法和_CommandPtr中的Execute方法类似)。<BR>——打开一个库连接。先创建一个实例指针，再用Open打开一个库连接，它将返回一个IUnknown的自动化接口指针。代码如下所示： _ConnectionPtr m_pConnection;<BR>// 初始化COM,创建ADO连接等操作<BR>AfxOleInit();<BR>m_pConnection.CreateInstance(__uuidof(Connection));<BR><BR>// 在ADO操作中建议语句中要常用try...catch()来捕获错误信息，<BR>// 因为它有时会经常出现一些意想不到的错误。jingzhou xu<BR>try <BR>{ <BR>// 打开本地Access库Demo.mdb<BR>m_pConnection-&gt;Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Demo.mdb","","",adModeUnknown);<BR>}<BR>catch(_com_error e)<BR>{<BR>AfxMessageBox("数据库连接失败，确认数据库Demo.mdb是否在当前路径下!");<BR>return FALSE;<BR>} <BR>——关闭一个库连接。如果连接状态有效，则用Close方法关闭它并赋于它空值。代码如下所示： if(m_pConnection-&gt;State)<BR>m_pConnection-&gt;Close();<BR>m_pConnection= NULL; <BR>2、_RecordsetPtr智能指针，可以用来打开库内数据表，并可以对表内的记录、字段等进行各种操作。<BR>——打开数据表。打开库内表名为DemoTable的数据表，代码如下： _RecordsetPtr m_pRecordset;<BR>m_pRecordset.CreateInstance(__uuidof(Recordset));<BR><BR>// 在ADO操作中建议语句中要常用try...catch()来捕获错误信息，<BR>// 因为它有时会经常出现一些意想不到的错误。jingzhou xu<BR>try<BR>{<BR>m_pRecordset-&gt;Open("SELECT * FROM DemoTable", // 查询DemoTable表中所有字段<BR>theApp.m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针<BR>adOpenDynamic,<BR>adLockOptimistic,<BR>adCmdText);<BR>}<BR>catch(_com_error *e)<BR>{<BR>AfxMessageBox(e-&gt;ErrorMessage());<BR>} <BR>——读取表内数据。将表内数据全部读出并显示在列表框内，m_AccessList为列表框的成员变量名。如果没有遇到表结束标志adoEOF，则用GetCollect(字段名)或m_pRecordset-&gt;Fields-&gt;GetItem(字段名)-&gt;Value方法，来获取当前记录指针所指的字段值，然后再用MoveNext()方法移动到下一条记录位置。代码如下所示： _variant_t var;<BR>CString strName,strAge;<BR>try<BR>{<BR>if(!m_pRecordset-&gt;BOF)<BR>m_pRecordset-&gt;MoveFirst();<BR>else<BR>{<BR>AfxMessageBox("表内数据为空");<BR>return;<BR>}<BR><BR>// 读入库中各字段并加入列表框中<BR>while(!m_pRecordset-&gt;adoEOF)<BR>{<BR>var = m_pRecordset-&gt;GetCollect("Name");<BR>if(var.vt != VT_NULL)<BR>strName = (LPCSTR)_bstr_t(var);<BR>var = m_pRecordset-&gt;GetCollect("Age");<BR>if(var.vt != VT_NULL)<BR>strAge = (LPCSTR)_bstr_t(var);<BR><BR>m_AccessList.AddString( strName + " --&gt; "+strAge );<BR><BR>m_pRecordset-&gt;MoveNext();<BR>}<BR><BR>// 默认列表指向第一项，同时移动记录指针并显示<BR>m_AccessList.SetCurSel(0);<BR>}<BR>catch(_com_error *e)<BR>{<BR>AfxMessageBox(e-&gt;ErrorMessage());<BR>} <BR>——插入记录。可以先用AddNew()方法新增一个空记录，再用PutCollect(字段名,值)输入每个字段的值，最后再Update()更新到库中数据既可。其中变量m_Name和m_Age分别为姓名及年龄编辑框的成员变量名。代码所下所示： try<BR>{<BR>// 写入各字段值<BR>m_pRecordset-&gt;AddNew();<BR>m_pRecordset-&gt;PutCollect("Name", _variant_t(m_Name));<BR>m_pRecordset-&gt;PutCollect("Age", atol(m_Age));<BR>m_pRecordset-&gt;Update();<BR><BR>AfxMessageBox("插入成功!");<BR>}<BR>catch(_com_error *e)<BR>{<BR>AfxMessageBox(e-&gt;ErrorMessage());<BR>} <BR>——移动记录指针。移动记录指针可以通过MoveFirst()方法移动到第一条记录、MoveLast()方法移动到最后一条记录、MovePrevious()方法移动到当前记录的前一条记录、MoveNext()方法移动到当前记录的下一条记录。但我们有时经常需要随意移动记录指针到任意记录位置时，可以使用Move(记录号)方法来实现，注意: Move()方法是相对于当前记录来移动指针位置的，正值向后移动、负值向前移动，如：Move(3)，当前记录是3时，它将从记录3开始往后再移动3条记录位置。代码如下所示： try<BR>{<BR>int curSel = m_AccessList.GetCurSel(); <BR>// 先将指针移向第一条记录，然后就可以相对第一条记录来随意移动记录指针<BR>m_pRecordset-&gt;MoveFirst();<BR>m_pRecordset-&gt;Move(long(curSel));<BR><BR>}<BR>catch(_com_error *e)<BR>{<BR>AfxMessageBox(e-&gt;ErrorMessage());<BR>} <BR>——修改记录中字段值。可以将记录指针移动到要修改记录的位置处，直接用PutCollect(字段名，值)将新值写入并Update()更新数据库既可。可以用上面方法移动记录指针，修改字段值代码如下所示： try<BR>{<BR>// 假设对第二条记录进行修改<BR>m_pRecordset-&gt;MoveFirst();<BR>m_pRecordset-&gt;Move(1); // 从0开始<BR>m_pRecordset-&gt;PutCollect("Name", _variant_t(m_Name));<BR>m_pRecordset-&gt;PutCollect("Age", atol(m_Age));<BR>m_pRecordset-&gt;Update();<BR>}<BR>catch(_com_error *e)<BR>{<BR>AfxMessageBox(e-&gt;ErrorMessage());<BR>} <BR>——删除记录。删除记录和上面修改记录的操作类似，先将记录指针移动到要修改记录的位置，直接用Delete()方法删除它并用Update()来更新数据库既可。代码如下所示： try<BR>{<BR>// 假设删除第二条记录<BR>m_pRecordset-&gt;MoveFirst();<BR>m_pRecordset-&gt;Move(1); // 从0开始<BR>m_pRecordset-&gt;Delete(adAffectCurrent); // 参数adAffectCurrent为删除当前记录<BR>m_pRecordset-&gt;Update();<BR>}<BR>catch(_com_error *e)<BR>{<BR>AfxMessageBox(e-&gt;ErrorMessage());<BR>} <BR>——关闭记录集。直接用Close方法关闭记录集并赋于其空值。代码如下所示： m_pRecordset-&gt;Close();<BR>m_pRecordset = NULL; <BR>3、CommandPtr智能指针，可以使用_ConnectionPtr或_RecordsetPtr来执行任务，定义输出参数，执行存储过程或SQL语句。 <BR>——执行SQL语句。先创建一个_CommandPtr实例指针，再将库连接和SQL语句做为参数，执行Execute()方法既可。代码如下所示： _CommandPtr m_pCommand;<BR>m_pCommand.CreateInstance(__uuidof(Command));<BR>m_pCommand-&gt;ActiveConnection = m_pConnection; // 将库连接赋于它<BR>m_pCommand-&gt;CommandText = "SELECT * FROM DemoTable"; // SQL语句<BR>m_pRecordset = m_pCommand-&gt;Execute(NULL, NULL,adCmdText); // 执行SQL语句，返回记录集 <BR>——执行存储过程。执行存储过程的操作和上面执行SQL语句类似，不同点仅是CommandText参数中不再是SQL语句，而是存储过程的名字，如Demo。另一个不同点就是在Execute()中参数由adCmdText(执行SQL语句)，改为adCmdStoredProc来执行存储过程。如果存储过程中存在输入、输出参数的话，需要使用到另一个智能指针_ParameterPtr来逐次设置要输入、输出的参数信息，并将其赋于_CommandPtr中Parameters参数来传递信息，有兴趣的读者可以自行查找相关书籍或MSDN。执行存储过程的代码如下所示： _CommandPtr m_pCommand;<BR>m_pCommand.CreateInstance(__uuidof(Command));<BR>m_pCommand-&gt;ActiveConnection = m_pConnection; // 将库连接赋于它<BR>m_pCommand-&gt;CommandText = "Demo"; <BR>m_pCommand-&gt;Execute(NULL,NULL, adCmdStoredProc); <BR>最后，如果想知道详细实现细节的话，可以在下载示例源码后，仔细查看源码既可(内有详细注释)。 <BR></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR></P></SPAN></TD></TR></TBODY></TABLE></SPAN></P>
<P><SPAN lang=EN-US><STRONG><FONT face="Times New Roman">&nbsp;&nbsp; </FONT></STRONG></SPAN><BR></P>]]></description>
</item><item>
<title><![CDATA[Window和Linux下TOMCAT中配置SSL（单项认证）]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=fishyqd&amp;id=12905</link>
<author>fishyqd</author>
<pubDate>2006/3/25 23:27:47</pubDate>
<description><![CDATA[<A><FONT size=1>　</FONT></A>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=1><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">一、</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">Windows XP</FONT></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=1><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">（</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">1</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">Tomcat </FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">：</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">jakarta-tomcat-<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /><st1:chsdate w:st="on" Year="1899" Month="12" Day="30" IsLunarDate="False" IsROCDate="False">5.5.9</st1:chsdate>.zip<SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>JDK : jdk-1_5_0_06-windows-i586-p.exe.</FONT></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=1>或者</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=1><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">（</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">2</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">Tomcat </FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">：</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">jakarta-tomcat-<st1:chsdate w:st="on" Year="1899" Month="12" Day="30" IsLunarDate="False" IsROCDate="False">5.0.9</st1:chsdate>.zip<SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>JDK : jdk-1_4_2_07-windows-i586-p.exe.</FONT></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=1><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">注意版本要对应，</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">tomcat5.0</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">与</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">JDK1.5</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">不兼容；</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">tomcat5.5</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">与</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">JDK1.4</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">不兼容。</SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; tab-stops: list 18.0pt; mso-list: l2 level1 lfo1"><FONT size=1><SPAN lang=EN-US style="mso-fareast-font-family: 'Times New Roman'"><SPAN style="mso-list: Ignore"><FONT face="Times New Roman">1，<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp; </SPAN></FONT></SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">安装</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">JDK</FONT></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 18pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=1>设置路径</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 18pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><IMG style="BORDER-LEFT-COLOR: #000000; BORDER-BOTTOM-COLOR: #000000; BORDER-TOP-COLOR: #000000; BORDER-RIGHT-COLOR: #000000" src="http://blogger.org.cn/blog/uploadfile/2006325232849724.PNG" border=0></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 18pt"><SPAN lang=EN-US><?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /><v:shapetype id=_x0000_t75 stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600"><v:stroke joinstyle="miter"></v:stroke><v:formulas><v:f eqn="if lineDrawn pixelLineWidth 0"></v:f><v:f eqn="sum @0 1 0"></v:f><v:f eqn="sum 0 0 @1"></v:f><v:f eqn="prod @2 1 2"></v:f><v:f eqn="prod @3 21600 pixelWidth"></v:f><v:f eqn="prod @3 21600 pixelHeight"></v:f><v:f eqn="sum @0 0 1"></v:f><v:f eqn="prod @6 1 2"></v:f><v:f eqn="prod @7 21600 pixelWidth"></v:f><v:f eqn="sum @8 21600 0"></v:f><v:f eqn="prod @7 21600 pixelHeight"></v:f><v:f eqn="sum @10 21600 0"></v:f></v:formulas><v:path o:connecttype="rect" gradientshapeok="t" o:extrusionok="f"></v:path><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:lock aspectratio="t" v:ext="edit"></o:lock></v:shapetype></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; tab-stops: list 18.0pt; mso-list: l2 level1 lfo1"><FONT size=1><SPAN lang=EN-US style="mso-fareast-font-family: 'Times New Roman'"><SPAN style="mso-list: Ignore"><FONT face="Times New Roman">2，<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp; </SPAN></FONT></SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">安装</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">tomcat</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，将</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">.zip</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">文件解压</SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; tab-stops: list 18.0pt; mso-list: l2 level1 lfo1"><FONT size=1><SPAN lang=EN-US style="mso-fareast-font-family: 'Times New Roman'"><SPAN style="mso-list: Ignore"><FONT face="Times New Roman">3，<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp; </SPAN></FONT></SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">运行</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">tomcat</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，将路径转为</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">%tomcat%/bin</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">下运行</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">startup.bat</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，即启动</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">tomcat</FONT></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; tab-stops: list 18.0pt; mso-list: l2 level1 lfo1"><FONT size=1><SPAN lang=EN-US style="mso-fareast-font-family: 'Times New Roman'"><SPAN style="mso-list: Ignore"><FONT face="Times New Roman"><IMG style="BORDER-LEFT-COLOR: #000000; BORDER-BOTTOM-COLOR: #000000; BORDER-TOP-COLOR: #000000; BORDER-RIGHT-COLOR: #000000" src="http://blogger.org.cn/blog/uploadfile/2006325232926218.PNG" border=0></FONT></SPAN></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; tab-stops: list 18.0pt; mso-list: l2 level1 lfo1"><FONT size=1><SPAN lang=EN-US style="mso-fareast-font-family: 'Times New Roman'"><SPAN style="mso-list: Ignore"><FONT face="Times New Roman">4，<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp; </SPAN></FONT></SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在浏览器中输入：</SPAN><SPAN lang=EN-US><A href="http://localhost:8080/"><FONT face="Times New Roman">http://localhost:8080</FONT></A><FONT face="Times New Roman">,</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">测试</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">tomcat</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">安装是否成功。如果成功会出现</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">tomcat</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">页面。</SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; tab-stops: list 18.0pt; mso-list: l2 level1 lfo1"><FONT size=1><SPAN lang=EN-US style="mso-fareast-font-family: 'Times New Roman'"><SPAN style="mso-list: Ignore"><FONT face="Times New Roman">5，<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp; </SPAN></FONT></SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">生成证书，依照如下步骤生成证书，注意：证书</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">(testkey)</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的密码和</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">keystore</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的密码一定要保持一致，即在最后一步输入回车。</SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><SPAN style="mso-spacerun: yes"><FONT face="Times New Roman" size=1>&nbsp;<IMG style="BORDER-LEFT-COLOR: #000000; BORDER-BOTTOM-COLOR: #000000; BORDER-TOP-COLOR: #000000; BORDER-RIGHT-COLOR: #000000" src="http://blogger.org.cn/blog/uploadfile/200632523302236.PNG" border=0></FONT></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=1><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">Window XP</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">下，生成的证书在</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">C:\</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">（即在运行</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">keytool</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">命令的路径下）下。</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">.</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">将证书</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">copy</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">到</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">%Tomcat%</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">目录下。</SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; tab-stops: list 18.0pt; mso-list: l2 level1 lfo1"><FONT size=1><SPAN lang=EN-US style="mso-fareast-font-family: 'Times New Roman'"><SPAN style="mso-list: Ignore"><FONT face="Times New Roman">6，<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp; </SPAN></FONT></SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">修改</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">tomcat</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">server.xml</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">（</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">%Tomcat%/conf/</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">目录下）文件</SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=1><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">server.xml</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">文件中找到如下部分：</SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><FONT face="Times New Roman"><FONT size=1><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&lt;!-- Define a SSL HTTP/1.1 Connector on port 8443 --&gt;</FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><FONT face="Times New Roman" size=1>&lt;!--</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><FONT face="Times New Roman"><FONT size=1><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>&lt;Connector port="8443" maxHttpHeaderSize="8192"</FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><FONT face="Times New Roman"><FONT size=1><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>maxThreads="150" minSpareThreads="25" maxSpareThreads="75"</FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><FONT face="Times New Roman"><FONT size=1><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>enableLookups="false" disableUploadTimeout="true"</FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><FONT face="Times New Roman"><FONT size=1><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>acceptCount="100" scheme="https" secure="true"</FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><FONT face="Times New Roman"><FONT size=1><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>clientAuth="false" sslProtocol="TLS" /&gt;</FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><FONT face="Times New Roman"><FONT size=1><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>- -&gt;</FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=1>改为</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><FONT face="Times New Roman"><FONT size=1><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&lt;!-- Define a SSL HTTP/1.1 Connector on port 8443 --&gt;</FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><FONT face="Times New Roman"><FONT size=1><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>&lt;Connector port="8443" maxHttpHeaderSize="8192"</FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><FONT face="Times New Roman"><FONT size=1><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>maxThreads="150" minSpareThreads="25" maxSpareThreads="75"</FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><FONT face="Times New Roman"><FONT size=1><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>enableLookups="false" disableUploadTimeout="true"</FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><FONT face="Times New Roman"><FONT size=1><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>acceptCount="100" scheme="https" secure="true"</FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 84pt; mso-char-indent-count: 8.0"><FONT size=1><SPAN lang=EN-US><FONT face="Times New Roman">keystoreFile="</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">（你的</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">tomcat</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">路径）</SPAN><SPAN lang=EN-US><FONT face="Times New Roman"> \.keystore" keystorePass="changeit"</FONT></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><FONT face="Times New Roman"><FONT size=1><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>clientAuth="false" sslProtocol="TLS" /&gt;</FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; tab-stops: list 18.0pt; mso-list: l2 level1 lfo1"><FONT size=1><SPAN lang=EN-US style="mso-fareast-font-family: 'Times New Roman'"><SPAN style="mso-list: Ignore"><FONT face="Times New Roman">7，<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp; </SPAN></FONT></SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">重新启动</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">tomcat</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，输入</SPAN><SPAN lang=EN-US><A href="https://localhost:8443/"><FONT face="Times New Roman">https://localhost:8443</FONT></A></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">测试</SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 18pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=1>如果成功会出现</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 18pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"></SPAN><SPAN lang=EN-US><o:p><FONT face="Times New Roman" size=1><IMG style="BORDER-LEFT-COLOR: #000000; BORDER-BOTTOM-COLOR: #000000; BORDER-TOP-COLOR: #000000; BORDER-RIGHT-COLOR: #000000" src="http://blogger.org.cn/blog/uploadfile/2006325233040693.PNG" border=0>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=1><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">二，</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">Linux </FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">（只测试了</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">j2sdk-1_4_0-linux-i386-rpm.bin </FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">与</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">Tomcat<st1:chsdate w:st="on" Year="1899" Month="12" Day="30" IsLunarDate="False" IsROCDate="False">5.0.9</st1:chsdate></FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）</SPAN></FONT></P>
<P style="TEXT-JUSTIFY: inter-ideograph; TEXT-ALIGN: justify"><FONT size=1><SPAN lang=EN-US style="FONT-SIZE: 10.5pt; FONT-FAMILY: 黑体">1 </SPAN><SPAN style="FONT-SIZE: 10.5pt; FONT-FAMILY: 黑体">安装<SPAN lang=EN-US>JDK </SPAN>安装好后<SPAN lang=EN-US>JDK</SPAN>路径为<SPAN lang=EN-US> /usr/java/j2sdk<st1:chsdate w:st="on" Year="1899" Month="12" Day="30" IsLunarDate="False" IsROCDate="False">1.4.0</st1:chsdate><o:p></o:p></SPAN></SPAN></FONT></P>
<P style="TEXT-JUSTIFY: inter-ideograph; TEXT-ALIGN: justify"><FONT size=1><SPAN lang=EN-US style="FONT-SIZE: 10.5pt; FONT-FAMILY: 黑体"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN></SPAN><SPAN style="FONT-SIZE: 10.5pt; FONT-FAMILY: 黑体">并在<SPAN lang=EN-US> /etc/profile</SPAN>中文件最后加入：<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></FONT></P>
<P style="MARGIN-LEFT: 10.5pt; mso-para-margin-left: 1.0gd"><SPAN lang=EN-US style="FONT-SIZE: 10.5pt; FONT-FAMILY: 黑体"><FONT size=1>JAVA_HOME=/usr/java/j2sdk<st1:chsdate w:st="on" Year="1899" Month="12" Day="30" IsLunarDate="False" IsROCDate="False">1.4.0</st1:chsdate><o:p></o:p></FONT></SPAN></P>
<P style="MARGIN-LEFT: 10.5pt; mso-para-margin-left: 1.0gd"><SPAN lang=EN-US style="FONT-SIZE: 10.5pt; FONT-FAMILY: 黑体"><FONT size=1>export JAVA_HOME<o:p></o:p></FONT></SPAN></P>
<P style="MARGIN-LEFT: 10.5pt; mso-para-margin-left: 1.0gd"><SPAN lang=EN-US style="FONT-SIZE: 10.5pt; FONT-FAMILY: 黑体"><FONT size=1>JRE_HOME=/usr/java/j2sdk<st1:chsdate w:st="on" Year="1899" Month="12" Day="30" IsLunarDate="False" IsROCDate="False">1.4.0</st1:chsdate><o:p></o:p></FONT></SPAN></P>
<P style="MARGIN-LEFT: 10.5pt; mso-para-margin-left: 1.0gd"><SPAN lang=EN-US style="FONT-SIZE: 10.5pt; FONT-FAMILY: 黑体"><FONT size=1>export JRE_HOME<o:p></o:p></FONT></SPAN></P>
<P style="TEXT-INDENT: 10.5pt; mso-char-indent-count: 1.0"><SPAN lang=EN-US style="FONT-SIZE: 10.5pt; FONT-FAMILY: 黑体"><FONT size=1>CLASSPATH=/usr/java/j2sdk<st1:chsdate w:st="on" Year="1899" Month="12" Day="30" IsLunarDate="False" IsROCDate="False">1.4.0</st1:chsdate>/lib<o:p></o:p></FONT></SPAN></P>
<P style="MARGIN-LEFT: 10.5pt; mso-para-margin-left: 1.0gd"><SPAN lang=EN-US style="FONT-SIZE: 10.5pt; FONT-FAMILY: 黑体"><FONT size=1>export CLASSPATH<o:p></o:p></FONT></SPAN></P>
<P style="MARGIN-LEFT: 10.5pt; mso-para-margin-left: 1.0gd"><SPAN lang=EN-US style="FONT-SIZE: 10.5pt; FONT-FAMILY: 黑体"><FONT size=1>PATH=/usr/java/j2sdk<st1:chsdate w:st="on" Year="1899" Month="12" Day="30" IsLunarDate="False" IsROCDate="False">1.4.0</st1:chsdate>/bin:$PATH<o:p></o:p></FONT></SPAN></P>
<P><FONT size=1><B><SPAN lang=EN-US style="FONT-SIZE: 10.5pt">2</SPAN></B><B><SPAN style="FONT-SIZE: 10.5pt">．</SPAN></B><SPAN style="FONT-SIZE: 10.5pt">安装<SPAN lang=EN-US>tomcat<o:p></o:p></SPAN></SPAN></FONT></P>
<P style="TEXT-JUSTIFY: inter-ideograph; TEXT-ALIGN: justify"><FONT size=1><SPAN lang=EN-US style="FONT-SIZE: 10.5pt">&nbsp;&nbsp; </SPAN><SPAN style="FONT-SIZE: 10.5pt">设安装好的路径为<SPAN lang=EN-US> /usr/tomcat<st1:chsdate w:st="on" Year="1899" Month="12" Day="30" IsLunarDate="False" IsROCDate="False">5.0.9</st1:chsdate><o:p></o:p></SPAN></SPAN></FONT></P>
<P style="TEXT-JUSTIFY: inter-ideograph; TEXT-ALIGN: justify"><FONT size=1><SPAN lang=EN-US style="FONT-SIZE: 10.5pt"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN></SPAN><SPAN style="FONT-SIZE: 10.5pt; FONT-FAMILY: 黑体">并在<SPAN lang=EN-US> /etc/profile</SPAN>中文件最后加入：<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></FONT></P>
<P><SPAN lang=EN-US style="FONT-SIZE: 10.5pt; FONT-FAMILY: 黑体"><FONT size=1><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN>TOMCAT_HOME=/program/tomcat<st1:chsdate w:st="on" Year="1899" Month="12" Day="30" IsLunarDate="False" IsROCDate="False">5.0.9</st1:chsdate><o:p></o:p></FONT></SPAN></P>
<P style="MARGIN-LEFT: 21pt; mso-para-margin-left: 2.0gd"><SPAN lang=EN-US style="FONT-SIZE: 10.5pt; FONT-FAMILY: 黑体"><FONT size=1>export TOMCAT_HOME<o:p></o:p></FONT></SPAN></P>
<P style="MARGIN-LEFT: 21pt; mso-para-margin-left: 2.0gd"><SPAN style="FONT-SIZE: 10.5pt; FONT-FAMILY: 黑体"><FONT size=1>并在命令行中运行用：<SPAN lang=EN-US>source /etc/profile<o:p></o:p></SPAN></FONT></SPAN></P>
<P style="TEXT-JUSTIFY: inter-ideograph; TEXT-ALIGN: justify"><SPAN style="FONT-SIZE: 10.5pt; mso-bidi-font-weight: bold"><FONT size=1>３．启动<SPAN lang=EN-US>tomcat<o:p></o:p></SPAN></FONT></SPAN></P>
<P style="TEXT-JUSTIFY: inter-ideograph; TEXT-ALIGN: justify"><FONT size=1><SPAN lang=EN-US style="FONT-SIZE: 10.5pt; mso-bidi-font-weight: bold"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN></SPAN><SPAN style="FONT-SIZE: 10.5pt; mso-bidi-font-weight: bold">用<SPAN lang=EN-US>%tomcat%/bin/startup.sh</SPAN>命令启动<SPAN lang=EN-US>tomcat<o:p></o:p></SPAN></SPAN></FONT></P>
<P style="TEXT-JUSTIFY: inter-ideograph; MARGIN-LEFT: 18pt; TEXT-INDENT: -18pt; TEXT-ALIGN: justify; tab-stops: list 18.0pt; mso-list: l1 level1 lfo2"><FONT size=1><SPAN lang=EN-US style="FONT-SIZE: 10.5pt; mso-bidi-font-weight: bold"><SPAN style="mso-list: Ignore">4<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><SPAN style="FONT-SIZE: 10.5pt; mso-bidi-font-weight: bold">用</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt; mso-bidi-font-weight: bold"><A href="http://localhost:8080/">http://localhost:8080</A></SPAN><SPAN style="FONT-SIZE: 10.5pt; mso-bidi-font-weight: bold">来检测<SPAN lang=EN-US>tomcat</SPAN>安装是否成功<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></FONT></P>
<P style="TEXT-JUSTIFY: inter-ideograph; MARGIN-LEFT: 18pt; TEXT-INDENT: -18pt; TEXT-ALIGN: justify; tab-stops: list 18.0pt; mso-list: l1 level1 lfo2"><FONT size=1><SPAN lang=EN-US style="FONT-SIZE: 10.5pt"><SPAN style="mso-list: Ignore">5<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><SPAN style="FONT-SIZE: 10.5pt">生成证书，如在<SPAN lang=EN-US>Winxp</SPAN>下安装步骤相同（注意要把生成的证书<SPAN lang=EN-US>copy</SPAN>到<SPAN lang=EN-US>%tomcat%</SPAN>目录下）<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=1><SPAN lang=EN-US style="BACKGROUND: silver; mso-highlight: silver"><FONT face="Times New Roman">6</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">修改</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">tomcat</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">server.xml</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">（</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">%Tomcat%/conf/</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">目录下）文件</SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=1><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">server.xml</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">文件中找到如下部分：</SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><FONT face="Times New Roman"><FONT size=1><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&lt;!-- Define a SSL HTTP/1.1 Connector on port 8443 --&gt;</FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><FONT face="Times New Roman" size=1>&lt;!--</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><FONT face="Times New Roman"><FONT size=1><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>&lt;Connector port="8443" maxHttpHeaderSize="8192"</FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><FONT face="Times New Roman"><FONT size=1><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>maxThreads="150" minSpareThreads="25" maxSpareThreads="75"</FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><FONT face="Times New Roman"><FONT size=1><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>enableLookups="false" disableUploadTimeout="true"</FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><FONT face="Times New Roman"><FONT size=1><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>acceptCount="100" scheme="https" secure="true"</FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><FONT face="Times New Roman"><FONT size=1><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>clientAuth="false" sslProtocol="TLS" /&gt;</FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><FONT face="Times New Roman"><FONT size=1><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>- -&gt;</FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=1>改为</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=1><SPAN lang=EN-US><FONT face="Times New Roman">erver.xml</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">文件中找到如下部分：</SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><FONT face="Times New Roman"><FONT size=1><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&lt;!-- Define a SSL HTTP/1.1 Connector on port 8443 --&gt;</FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><FONT face="Times New Roman"><FONT size=1><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>&lt;Connector port="8443" maxHttpHeaderSize="8192"</FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><FONT face="Times New Roman"><FONT size=1><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>maxThreads="150" minSpareThreads="25" maxSpareThreads="75"</FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><FONT face="Times New Roman"><FONT size=1><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>enableLookups="false" disableUploadTimeout="true"</FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><FONT face="Times New Roman"><FONT size=1><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN>acceptCount="100" scheme="https" secure="true"</FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 84pt; mso-char-indent-count: 8.0"><FONT size=1><SPAN lang=EN-US><FONT face="Times New Roman">keystoreFile="</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">（你的</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">tomcat</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">路径）</SPAN><FONT face="Times New Roman"> <SPAN lang=EN-US>/.keystore" keystorePass="changeit"</SPAN></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><FONT face="Times New Roman"><FONT size=1><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>clientAuth="false" sslProtocol="TLS" /&gt;</FONT></FONT></SPAN></P>
<P style="TEXT-JUSTIFY: inter-ideograph; MARGIN-LEFT: 18pt; TEXT-INDENT: -18pt; TEXT-ALIGN: justify; tab-stops: list 18.0pt; mso-list: l0 level1 lfo3"><FONT size=1><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><SPAN style="mso-list: Ignore">7<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN>重新启动<SPAN lang=EN-US>tomcat</SPAN>，输入<SPAN lang=EN-US><A href="https://localhost:8443/">https://localhost:8443</A></SPAN>测试<SPAN lang=EN-US style="FONT-SIZE: 10.5pt"><o:p></o:p></SPAN></FONT></P>]]></description>
</item><item>
<title><![CDATA[ＭｙＳＱＬ数据库 与JAVA]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=fishyqd&amp;id=12904</link>
<author>fishyqd</author>
<pubDate>2006/3/25 23:09:56</pubDate>
<description><![CDATA[<A><FONT size=1>　</FONT></A><FONT size=1> </FONT>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><FONT size=1>一，<SPAN lang=EN-US>MySQL</SPAN>服务的启动与关闭<SPAN lang=EN-US><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><FONT size=1><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>(1)</SPAN><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">查看并启动</SPAN><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">MySQL</SPAN><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">服务。<SPAN lang=EN-US> <o:p></o:p></SPAN></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 150%; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-char-indent-count: 2.0" align=left><FONT size=1><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">在</SPAN><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">Windows XP</SPAN><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">下安装完</SPAN><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">MySQL</SPAN><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">后，它就已经自动启动服务了，并且在开始菜单中有其客户端的快捷方式连接，见图</SPAN><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">1</SPAN><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">。<SPAN lang=EN-US> <o:p></o:p></SPAN></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 11.7pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><FONT size=1><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">&nbsp;<IMG style="BORDER-LEFT-COLOR: #000000; BORDER-BOTTOM-COLOR: #000000; BORDER-TOP-COLOR: #000000; BORDER-RIGHT-COLOR: #000000" src="http://blogger.org.cn/blog/uploadfile/2006325231833178.PNG" border=0></SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 11.7pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><FONT size=1><?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /><v:shapetype id=_x0000_t75 stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600"><v:stroke joinstyle="miter"></v:stroke><v:formulas><v:f eqn="if lineDrawn pixelLineWidth 0"></v:f><v:f eqn="sum @0 1 0"></v:f><v:f eqn="sum 0 0 @1"></v:f><v:f eqn="prod @2 1 2"></v:f><v:f eqn="prod @3 21600 pixelWidth"></v:f><v:f eqn="prod @3 21600 pixelHeight"></v:f><v:f eqn="sum @0 0 1"></v:f><v:f eqn="prod @6 1 2"></v:f><v:f eqn="prod @7 21600 pixelWidth"></v:f><v:f eqn="sum @8 21600 0"></v:f><v:f eqn="prod @7 21600 pixelHeight"></v:f><v:f eqn="sum @10 21600 0"></v:f></v:formulas><v:path o:connecttype="rect" gradientshapeok="t" o:extrusionok="f"></v:path><o:lock aspectratio="t" v:ext="edit"></o:lock></v:shapetype><o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center; mso-pagination: widow-orphan" align=center><FONT size=1><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">图</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">1 <o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm -25.6pt 11.7pt 0cm; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-para-margin-top: 0cm; mso-para-margin-right: -2.44gd; mso-para-margin-bottom: 11.7pt; mso-para-margin-left: 0cm" align=left><FONT size=1><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">&nbsp;<SPAN style="mso-tab-count: 1">&nbsp;&nbsp; </SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">可以通过</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">Windows</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">的服务管理器查看。“开始”－“运行”，输入“</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">services.msc</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">”，回车。弹出</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">Windows</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">的服务管理器，然后就可以看见服务名为“</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">mysql</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">”的服务项了，其右边标明“已启动”，见图<SPAN lang=EN-US>2<SPAN style="mso-spacerun: yes">&nbsp; </SPAN></SPAN></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm -25.6pt 11.7pt 0cm; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-para-margin-top: 0cm; mso-para-margin-right: -2.44gd; mso-para-margin-bottom: 11.7pt; mso-para-margin-left: 0cm" align=left><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><SPAN lang=EN-US><SPAN style="mso-spacerun: yes"></SPAN><o:p><FONT size=1><IMG style="BORDER-LEFT-COLOR: #000000; BORDER-BOTTOM-COLOR: #000000; BORDER-TOP-COLOR: #000000; BORDER-RIGHT-COLOR: #000000" src="http://blogger.org.cn/blog/uploadfile/2006325231945964.PNG" border=0></FONT></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center; mso-pagination: widow-orphan" align=center><FONT size=1><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">图</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">2 <o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 11.7pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><FONT size=1><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">&nbsp;</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 150%; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-char-indent-count: 2.0" align=left><FONT size=1><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">如果没有“已启动”字样，说明</SPAN><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">MySQL</SPAN><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">服务未启动，不能连接，会出现</SPAN><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">10061</SPAN><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">错误。启动方法为：“开始”－“运行”，输入“</SPAN><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">cmd</SPAN><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">”，回车弹出</SPAN><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">XP</SPAN><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">命令提示符界面（类似</SPAN><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">DOS</SPAN><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">命令行，以后简称命令行）。然后输入“</SPAN><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">net start mysql</SPAN><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">”就启动</SPAN><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">mysql</SPAN><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">服务了，停止</SPAN><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">mysql</SPAN><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">服务“</SPAN><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">net stop mysql</SPAN><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">”（注意，这里是输入的</SPAN><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">MySQL</SPAN><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">服务的名字。如果你的</SPAN><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">MySQL</SPAN><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">服务的名字是</SPAN><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">DB</SPAN><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">或其它名字，你应该输入“</SPAN><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">net start DB</SPAN><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">”或其它名），见图</SPAN><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">3</SPAN><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">。</SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 150%; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-char-indent-count: 2.0" align=left><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><SPAN lang=EN-US><FONT size=1><IMG style="BORDER-LEFT-COLOR: #000000; BORDER-BOTTOM-COLOR: #000000; BORDER-TOP-COLOR: #000000; BORDER-RIGHT-COLOR: #000000" src="http://blogger.org.cn/blog/uploadfile/2006325232028431.PNG" border=0>&nbsp;<o:p></o:p></FONT></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 11.7pt; LINE-HEIGHT: 150%; TEXT-ALIGN: center; mso-pagination: widow-orphan" align=center><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><o:p><FONT size=1></FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 150%; TEXT-ALIGN: center; mso-pagination: widow-orphan; mso-char-indent-count: 2.0" align=center><FONT size=1><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">图</SPAN><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">3 <o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 11.7pt; LINE-HEIGHT: 150%; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><FONT size=1><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">&nbsp;</SPAN><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">(2)</SPAN><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">连接</SPAN><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">MySQL</SPAN><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">服务器。<SPAN lang=EN-US> <o:p></o:p></SPAN></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 150%; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-char-indent-count: 2.0" align=left><FONT size=1><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">现在开始连接</SPAN><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">MySQL</SPAN><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">服务器，连接</SPAN><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">MySQL</SPAN><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">的命令格式为：<SPAN lang=EN-US> <o:p></o:p></SPAN></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21.1pt; LINE-HEIGHT: 150%; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-char-indent-count: 2.0" align=left><FONT size=1><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="COLOR: red; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">mysql –h </SPAN></B><B style="mso-bidi-font-weight: normal"><SPAN style="COLOR: red; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">主机名</SPAN></B><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="COLOR: red; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt"> –u </SPAN></B><B style="mso-bidi-font-weight: normal"><SPAN style="COLOR: red; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">用户名</SPAN></B><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="COLOR: red; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt"> –p </SPAN></B><B style="mso-bidi-font-weight: normal"><SPAN style="COLOR: red; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">用户密码<SPAN lang=EN-US> <o:p></o:p></SPAN></SPAN></B></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 150%; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-char-indent-count: 2.0" align=left><FONT size=1><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">在命令行进入</SPAN><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">MySQL</SPAN><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">的目录，见图</SPAN><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">4</SPAN><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">。<SPAN lang=EN-US> <o:p></o:p></SPAN></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 11.7pt; LINE-HEIGHT: 150%; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><FONT size=1><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">&nbsp;<IMG style="BORDER-LEFT-COLOR: #000000; BORDER-BOTTOM-COLOR: #000000; BORDER-TOP-COLOR: #000000; BORDER-RIGHT-COLOR: #000000" src="http://blogger.org.cn/blog/uploadfile/200632523212807.PNG" border=0></SPAN><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 150%; TEXT-ALIGN: center; mso-pagination: widow-orphan; mso-char-indent-count: 2.0" align=center><FONT size=1><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">图</SPAN><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">4 <o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 150%; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-char-indent-count: 2.0" align=left><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><FONT size=1>由于我在开始时没有设置密码，所以直接按回车就可以了。如果出现：<SPAN lang=EN-US> <o:p></o:p></SPAN></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 150%; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-char-indent-count: 2.0" align=left><I style="mso-bidi-font-style: normal"><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt"><FONT size=1>Welcome to the MySQL monitor.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>Commands end with ; or \g. <o:p></o:p></FONT></SPAN></I></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 150%; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-char-indent-count: 2.0" align=left><I style="mso-bidi-font-style: normal"><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt"><FONT size=1>Your MySQL connection id is 1 to server version: <?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /><st1:chsdate w:st="on" Year="1899" Month="12" Day="30" IsLunarDate="False" IsROCDate="False">4.1.11</st1:chsdate>-nt <o:p></o:p></FONT></SPAN></I></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 150%; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-char-indent-count: 2.0" align=left><I style="mso-bidi-font-style: normal"><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt"><FONT size=1>Type 'help;' or '\h' for help. Type '\c' to clear the buffer. <o:p></o:p></FONT></SPAN></I></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 150%; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-char-indent-count: 2.0" align=left><I style="mso-bidi-font-style: normal"><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt"><FONT size=1>mysql&gt; <o:p></o:p></FONT></SPAN></I></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 150%; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-char-indent-count: 2.0" align=left><FONT size=1><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">这就说明连接</SPAN><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">MySQL</SPAN><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">成功，“</SPAN><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">mysql&gt;</SPAN><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">”说明已经成功联入</SPAN><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">MySQL</SPAN><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">服务器了，可以开始</SPAN><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">msql</SPAN><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">的操作了。<SPAN lang=EN-US> <o:p></o:p></SPAN></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 150%; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-char-indent-count: 2.0" align=left><FONT size=1><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">“</SPAN><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">-h </SPAN><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">主机名”还可以这样写：“</SPAN><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">-h</SPAN><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">主机名”（中间不要空格）、“</SPAN><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">--host=</SPAN><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">主机名”<SPAN lang=EN-US> <o:p></o:p></SPAN></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 150%; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-char-indent-count: 2.0" align=left><FONT size=1><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">“</SPAN><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">-u </SPAN><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">用户名”还可以写成：“</SPAN><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">-u </SPAN><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">用户名”、“</SPAN><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">--user=</SPAN><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">用户名”<SPAN lang=EN-US> <o:p></o:p></SPAN></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 150%; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-char-indent-count: 2.0" align=left><FONT size=1><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">“</SPAN><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">-p </SPAN><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">用户密码”还可以写出：“</SPAN><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">--password=</SPAN><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">用户密码”。但是，出于安全的考虑，最好不要这样做。选择</SPAN><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">-p </SPAN><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">不跟口令告诉</SPAN><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">mysql</SPAN><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">在启动时提示您键入口令。例如：<SPAN lang=EN-US> <o:p></o:p></SPAN></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 150%; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-char-indent-count: 2.0" align=left><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt"><FONT size=1>mysql&gt;mysql -hlocalhost –u root -p <o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 150%; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-char-indent-count: 2.0" align=left><SPAN lang=EN-US style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><FONT size=1><SPAN style="mso-spacerun: yes">&nbsp;</SPAN><o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=1><SPAN style="BACKGROUND: silver; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-highlight: silver">二</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"> 安装<SPAN lang=EN-US>MySQL-Front</SPAN>（可选 <SPAN lang=EN-US>Mysql-front</SPAN>下载地址：<SPAN lang=EN-US>http://www.mysqlfront.de/</SPAN>）<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 3.35pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 150%; mso-outline-level: 3"><SPAN lang=EN-US style="COLOR: black; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial; mso-bidi-font-weight: bold"><A href="http://mikespook.cnblogs.com/archive/2005/04/22/143259.html"><FONT size=1><SPAN style="COLOR: black; TEXT-DECORATION: none; text-underline: none">MySQL-Front</SPAN><SPAN lang=EN-US style="COLOR: black; TEXT-DECORATION: none; text-underline: none"><SPAN lang=EN-US>，MySQL</SPAN></SPAN><SPAN lang=EN-US style="COLOR: black; TEXT-DECORATION: none; text-underline: none"><SPAN lang=EN-US>的企业管理器</SPAN></SPAN></FONT></A><FONT size=1> </FONT></SPAN><FONT size=1><SPAN style="COLOR: black; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial; mso-bidi-font-weight: bold">。</SPAN><SPAN style="COLOR: black; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial">如果对<SPAN lang=EN-US>phpMyAdmin</SPAN>更换不同的服务器就要去修改<SPAN lang=EN-US>config.inc.php</SPAN>感到厌倦，并且想得到调试<SPAN lang=EN-US>SQL</SPAN>时更好的用户体验的话，可以试试这个工具<SPAN lang=EN-US>——MySQL-Front</SPAN>（全功能试用<SPAN lang=EN-US>30</SPAN>天，之后只能使用部分功能。也可以去下<SPAN lang=EN-US>1.0</SPAN>，完全是免费的版本。）。<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 3.35pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 150%; mso-outline-level: 3"><SPAN style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1>注意，只有先启动了<SPAN lang=EN-US>MySQL</SPAN>后才能依靠<SPAN lang=EN-US>MySQL-Front</SPAN>登录到<SPAN lang=EN-US>MySQL</SPAN>服务器上。不能依靠<SPAN lang=EN-US>MySQL-Front</SPAN>启动<SPAN lang=EN-US>MySQL</SPAN>服务器。<SPAN lang=EN-US><o:p></o:p></SPAN></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 3.35pt 21pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 150%; mso-outline-level: 3"><SPAN style="COLOR: black; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial"><FONT size=1>登录界面如图<SPAN lang=EN-US>5<o:p></o:p></SPAN></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 3.35pt 21pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 150%; mso-outline-level: 3"><SPAN lang=EN-US style="COLOR: black; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial"><o:p><FONT size=1></FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 3.35pt 21pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 150%; mso-outline-level: 3"><SPAN style="COLOR: black; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial"><FONT size=1><IMG style="BORDER-LEFT-COLOR: #000000; BORDER-BOTTOM-COLOR: #000000; BORDER-TOP-COLOR: #000000; BORDER-RIGHT-COLOR: #000000" src="http://blogger.org.cn/blog/uploadfile/2006325232143379.PNG" border=0></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 3.35pt 21pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 150%; mso-outline-level: 3"><SPAN style="COLOR: black; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial"><FONT size=1>图<SPAN lang=EN-US>5<o:p></o:p></SPAN></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 3.35pt 21pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 150%; mso-outline-level: 3"><FONT size=1><SPAN style="COLOR: black; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial">登录后界面，见图<SPAN lang=EN-US>6</SPAN></SPAN><SPAN style="COLOR: black; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial"><IMG style="BORDER-LEFT-COLOR: #000000; BORDER-BOTTOM-COLOR: #000000; BORDER-TOP-COLOR: #000000; BORDER-RIGHT-COLOR: #000000" src="http://blogger.org.cn/blog/uploadfile/2006325232220995.PNG" border=0></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 3.35pt 21pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 150%; TEXT-ALIGN: center; mso-outline-level: 3" align=center><SPAN style="COLOR: black; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial"><FONT size=1>图<SPAN lang=EN-US>6<o:p></o:p></SPAN></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=1><SPAN style="BACKGROUND: silver; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-highlight: silver">三</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"> <SPAN lang=EN-US>JAVA</SPAN>连接<SPAN lang=EN-US>MySQL<o:p></o:p></SPAN></SPAN></FONT></P>
<P><SPAN style="FONT-SIZE: 10.5pt"><FONT size=1>所需插件<SPAN lang=EN-US>mysql-connector-java-<st1:chsdate w:st="on" Year="1899" Month="12" Day="30" IsLunarDate="False" IsROCDate="False">3.1.5</st1:chsdate>-gamma-bin.jar<o:p></o:p></SPAN></FONT></SPAN></P>
<P><SPAN style="FONT-SIZE: 10.5pt"><FONT size=1>下载地址<SPAN lang=EN-US><A href="http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-3.1.5-gamma.zip/from/http:/mirrors.hpcf.upr.edu/mysql/">http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-3.1.5-gamma.zip/from/http://mirrors.hpcf.upr.edu/mysql/</A><o:p></o:p></SPAN></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1>注：在用这个插件前我用<SPAN lang=EN-US>mm.mysql-<st1:chsdate w:st="on" Year="1899" Month="12" Day="30" IsLunarDate="False" IsROCDate="False">2.0.4</st1:chsdate>-bin.jar</SPAN>作为与<SPAN lang=EN-US>MySQL</SPAN>连接的数据库插件，可是在调适下面示例代码时出现：<STRONG><SPAN lang=EN-US style="FONT-FAMILY: 宋体">Communication failure during handshake. Is there a server running on localhost:3306?</SPAN></STRONG><STRONG><SPAN style="FONT-FAMILY: 宋体">错误。</SPAN></STRONG><STRONG><SPAN style="FONT-WEIGHT: normal; FONT-FAMILY: 宋体; mso-bidi-font-weight: bold">故如果用</SPAN></STRONG><SPAN lang=EN-US>mm.mysql-2.0.4-bin.jar</SPAN>出现如上问题，请换成插件<SPAN lang=EN-US>mysql-connector-java-3.1.5-gamma-bin.jar</SPAN>试一下<STRONG><SPAN lang=EN-US style="FONT-WEIGHT: normal; FONT-FAMILY: 宋体; mso-bidi-font-weight: bold"><o:p></o:p></SPAN></STRONG></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体"><o:p><FONT size=1>&nbsp;</FONT></o:p></SPAN></P><PRE style="BACKGROUND: white"><FONT face=宋体><FONT size=1><SPAN style="mso-bidi-font-size: 10.5pt">另外如果在使用数据库了时出现以下错误：</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10.5pt">ERROR: database: mysql_error: Client does not support authentication &nbsp;protocol request by server; consider upgrading MySQL client Fatal Error, Quitting..</SPAN></FONT></FONT></PRE>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体"><FONT size=1>按如下方法解决：<SPAN lang=EN-US><o:p></o:p></SPAN></FONT></SPAN></P>
<P class=MsoNormal style="BACKGROUND: white; MARGIN: 0cm 0cm 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=1>解决方法如下：</FONT></SPAN></P>
<P class=MsoNormal style="BACKGROUND: white; MARGIN: 0cm 0cm 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"><FONT size=1><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">（摘自</SPAN><SPAN lang=EN-US><A href="http://sourceforge.net/mailarchive/forum.php?thread_id=7899059&amp;forum_id=7142"><FONT face="Times New Roman">http://sourceforge.net/mailarchive/forum.php?thread_id=7899059&amp;forum_id=7142</FONT></A></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）</SPAN></FONT></P><PRE style="BACKGROUND: white"><SPAN lang=EN-US style="FONT-SIZE: 10.5pt"><FONT face=宋体 size=1>This error is generated because snort is compiled with old MySQL libraries</FONT></SPAN></PRE><PRE style="BACKGROUND: white"><SPAN lang=EN-US style="FONT-SIZE: 10.5pt"><FONT face=宋体 size=1> that doesn"t support the new MySQL 4.1 password encryption. To resolve this</FONT></SPAN></PRE><PRE style="BACKGROUND: white"><SPAN lang=EN-US style="FONT-SIZE: 10.5pt"><FONT face=宋体 size=1> issue, you have to enter the following:</FONT></SPAN></PRE><PRE style="BACKGROUND: white"><SPAN lang=EN-US style="FONT-SIZE: 10.5pt"><FONT face=宋体 size=1> </FONT></SPAN></PRE><PRE style="BACKGROUND: white"><SPAN lang=EN-US style="FONT-SIZE: 10.5pt"><FONT face=宋体 size=1>&nbsp;mysql&gt; SET PASSWORD FOR</FONT></SPAN></PRE><PRE style="BACKGROUND: white"><SPAN lang=EN-US style="FONT-SIZE: 10.5pt"><FONT face=宋体 size=1>&nbsp;&nbsp;&nbsp;&nbsp; -&gt; "some_user"@"some_host" = OLD_PASSWORD("newpwd");</FONT></SPAN></PRE><PRE style="BACKGROUND: white"><SPAN lang=EN-US style="FONT-SIZE: 10.5pt"><FONT face=宋体 size=1> </FONT></SPAN></PRE><PRE style="BACKGROUND: white"><SPAN lang=EN-US style="FONT-SIZE: 10.5pt"><FONT face=宋体 size=1>&nbsp;Alternatively, use UPDATE and FLUSH PRIVILEGES: </FONT></SPAN></PRE><PRE style="BACKGROUND: white"><SPAN lang=EN-US style="FONT-SIZE: 10.5pt"><FONT face=宋体 size=1>&nbsp;</FONT></SPAN></PRE><PRE style="BACKGROUND: white"><SPAN lang=EN-US style="FONT-SIZE: 10.5pt"><FONT face=宋体 size=1>&nbsp;mysql&gt; UPDATE mysql.user SET Password = OLD_PASSWORD("newpwd")</FONT></SPAN></PRE><PRE style="BACKGROUND: white"><SPAN lang=EN-US style="FONT-SIZE: 10.5pt"><FONT face=宋体 size=1>&nbsp;&nbsp;&nbsp;&nbsp; -&gt; WHERE Host = "some_host" AND User = "some_user";</FONT></SPAN></PRE><PRE style="BACKGROUND: white"><FONT face=宋体><FONT size=1><SPAN lang=EN-US style="FONT-SIZE: 10.5pt"> mysql&gt; FLUSH PRIVILEGES</SPAN><SPAN style="FONT-SIZE: 10.5pt">；</SPAN></FONT></FONT></PRE>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=1><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体">JAVA</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体">连接<SPAN lang=EN-US>MySQL</SPAN>示例代码<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1>package com.ideas.util;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><o:p><FONT size=1>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1>import java.sql.Connection;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1>import java.sql.DriverManager;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1>import java.sql.ResultSet;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1>import java.sql.SQLException;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1>import java.sql.Statement;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><o:p><FONT size=1>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1>public class sql_data {<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=1><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN>String sDBDriver = "com.mysql.jdbc.Driver";//</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt">如果用<SPAN lang=EN-US>mm.mysql-<st1:chsdate w:st="on" Year="1899" Month="12" Day="30" IsLunarDate="False" IsROCDate="False">2.0.4</st1:chsdate>-bin.jar</SPAN>，改为：<SPAN lang=EN-US>String sDBDriver = " org.gjt.mm.mysql.Driver";<o:p></o:p></SPAN></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN>String url =<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=1><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>"jdbc:mysql://localhost:3306/book";<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>//book</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt">要换成读者要连接的数据库<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=1><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN>//pubs</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt">为你的数据库的<SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></SPAN></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=1><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN>String user = "root";<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>//MySQL</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt">用户名<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=1><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN>String password = "111111";<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>//MySQL</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt">密码，以读者的密码为准<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN>Connection conn = null;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN>Statement stmt = null;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN>ResultSet rs = null;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN>public sql_data() {<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>try {<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>Class.forName(sDBDriver).newInstance();<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>} catch (java.lang.ClassNotFoundException e) {<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>System.err.println("sql_data(): " + e.getMessage());<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>catch (java.lang.Exception e) {<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>System.err.println("sql_data(): " + e.getMessage());<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1>public ResultSet executeQuery(String sql) {<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>try {<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>conn = DriverManager.getConnection(url, user, password);<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>stmt =<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1><SPAN style="mso-tab-count: 4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>conn.createStatement(<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1><SPAN style="mso-tab-count: 5">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>ResultSet.TYPE_SCROLL_SENSITIVE,<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1><SPAN style="mso-tab-count: 5">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>ResultSet.CONCUR_READ_ONLY);<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>rs = stmt.executeQuery(sql);<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>} catch (SQLException ex) {<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>System.err.println("sql_data.executeQuery:" + ex.getMessage());<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>return rs;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN>public void closeConn() {<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>try {<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>conn.close();<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>} catch (SQLException e) {<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>e.printStackTrace();<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN>public<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>static void main(String []args)<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>String title;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt"><FONT size=1><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>sql_data sqlbean = new sql_data();<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=1><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size]]></description>
</item>
</channel>
</rss>