⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 connection_examples.html

📁 通用的数据库中间库
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<html><head><meta name="KEYWORDS" content="      library, C++,       Oracle, SQLServer, DB2, Sybase, Informix, InterBase, SQLBase, ODBC, 
      SQL, server, client, database, programming, development, software, 
      Win32, Windows, Linux, Unix, Solaris,
      Microsoft, Borland, Centura, Gupta, IBM"><meta name="DESCRIPTION" content=
"SQLAPI++ is C++ library for accessing SQL databases (Oracle, SQLServer, Sybase, DB2, InterBase, SQLBase, Informix, ODBC).
It uses native APIs, provides low-level access to database-specific features."><title>SQLAPI++ Library - Online Documentation - SAConnection Examples</title></head><body bgcolor="#ffffff" BACKGROUND="../images/bg.gif" text="#000000"><!--GlbHdr--> <table WIDTH="600" height="40" frame="hsides" BORDER="2" BORDERCOLOR="#004fcd" align="right" cellpadding="0" cellspacing="2" id="TABLE1">
    
    <tr><!--class="GlbDefault"-->        
        <td width="70" bgcolor="#000094" bordercolor="black" align="middle"><A href="/index.html" style="TEXT-DECORATION: none">
			<font color="white" size="3" face="sans-serif">
			<b>Home</b></font></A></td></TD>
        <td width="70" bgcolor="#000094" bordercolor="black" align="middle"><A href="/HowTo/index.html" style="TEXT-DECORATION: none">			<font color="white" size="3" face="sans-serif">
			<b>How To</b></font></A></td><!--class="GlbActive"-->
        <td width="70" bgcolor="#00bb00" bordercolor="black" align="middle"><A href="/OnLineDoc/index.html" style="TEXT-DECORATION: none">			<font color="white" size="3" face="sans-serif">
			<b>Online Documentation</b></font></A></td><!--class="GlbDefault"-->        
		<td width="70" bgcolor="#000094" bordercolor="black" align="middle"><A href="/Support/index.html" style="TEXT-DECORATION: none">			<font color="white" size="3" face="sans-serif">
			<b>Support</b></font></A></td>
        <td width=70 bgcolor=#000094 bordercolor=black align=middle><A href="/Download/index.html" style="TEXT-DECORATION: none" >
			<font color=white size=3  face=sans-serif>
			<b>Download</b></font></A></td>
        <td width="70" bgcolor="#000094" bordercolor="black" align="middle"><A href="/Order/index.html" style="TEXT-DECORATION: none">			<font color="white" size="3" face="sans-serif">
			<b>Order</b></font></A></td>    </tr>
</table>&nbsp;

<p>&nbsp;</p>
<table width="100%">
	<tr>
		<td valign="top" width="165"><!--LeftMenu-->			
			<table frame="void" CELLSPACING="5" width="165">
				<tr><td><p>&nbsp;</p></td>
				</tr>
				<tr>
					<td><img align="middle" src="../images/green.gif" WIDTH="12" HEIGHT="12"><A href="Command.html" style="TEXT-DECORATION: none">
					<font color="white" size="2" face="sans-serif">
					SACommand</A> </FONT> </td>
				</tr>
				<tr>
					<td><img align="middle" src="../images/red.gif" WIDTH="12" HEIGHT="12"><A href="Connection.html" style="TEXT-DECORATION: none">
					<font color="white" size="2" face="sans-serif">
					SAConnection</A> </FONT> </td>
				</tr>
				<tr>
					<td><img align="middle" src="../images/green.gif" WIDTH="12" HEIGHT="12"><A href="Exception.html" style="TEXT-DECORATION: none">
					<font color="white" size="2" face="sans-serif">
					SAException</font></A> </td>
				</tr>
				<tr>
					<td><img align="middle" src="../images/green.gif" WIDTH="12" HEIGHT="12"><A href="Field.html" style="TEXT-DECORATION: none">
					<font color="white" size="2" face="sans-serif">
					SAField</A> </FONT> </td>
				</tr>
				<tr>
					<td><img align="middle" src="../images/green.gif" WIDTH="12" HEIGHT="12"><A href="Param.html" style="TEXT-DECORATION: none">
					<font color="white" size="2" face="sans-serif">
					SAParam</A> </FONT> </td>
				</tr>
				<tr><td><hr id=HR1></td></tr>
				<tr>
					<td><img align=middle src="../images/green.gif" WIDTH="12" HEIGHT="12">
					<A href="String.html" style ="TEXT-DECORATION: none" >
					<font color=white size=2 face=sans-serif>
					SAString</A> </FONT> </td>
				</tr>
				<tr>
					<td><img align=middle src="../images/green.gif" WIDTH="12" HEIGHT="12">
					<A href="DateTime.html" style ="TEXT-DECORATION: none" >
					<font color=white size=2 face=sans-serif>
					SADateTime</A> </FONT> </td>
				</tr>
			</table>
		</td><!--empty column-->
		<td width="20"> 
			<p>  </p>
		</td><!--Content-->
		<td valign="top" align="left">
			<table width="100%" cellspacing="2" cellpadding="2">
				<tr>
					<td align="left">	<A href="Connection.html" style="TEXT-DECORATION: none"><h3>Class Members</h3></A>
					</td>
					<td align="left">	<A href="Connection_Usage.html" style="TEXT-DECORATION: none"><h3>Usage</h3></A>
					</td>
				</tr>			
				<tr>
					<td colspan="2"><h1>SAConnection Examples</h1></td>
				</tr>			
			</table>
	  <HR id=HR1>
	  <A name=cnstr></A>
      <H3>SAConnection constructor</H3>
      <P><FONT face=Courier>/*<BR>Default constructor creates SAConnection object that 
      is not initially connected to database or associated with specific client. 
      You have to call SAConnection::setClient() and/or SAConnection::Connect() 
      later.<BR>*/</FONT><FONT face=Courier></FONT></P>
      <P><FONT face=Courier><STRONG>SAConnection con, con2;</STRONG> 
            </FONT></P>
	  <HR id=HR1>
	  <A name=dstr></A>
      <H3>SAConnection destructor</H3>
      <P><FONT face=Courier>/*<BR>Destructor&nbsp;deletes SAConnection object. It also 
      disconnect object from database if needed.<BR>*/</FONT><FONT face=Courier></FONT></P>
      <P><FONT face=Courier>SAConnection pCon = new <FONT 
      face=Courier>SAConnection</FONT>  ;</FONT></P>
      <P><FONT face=Courier>...</FONT></P>
      <P><FONT face=Courier><STRONG>delete pCon;</STRONG></FONT></P>

	  <HR id=HR1>
	  <A name=setClient></A>
      <H3>setClient</H3>
      <P><FONT face=Courier>/*<BR>     
      Exception handling is omitted for simplicity.<BR>*/</FONT><FONT face=Courier></FONT></P>
      <P><FONT face=Courier>SAConnection Con;</FONT></P>
      <P><FONT 
      face=Courier><STRONG>Con.setClient(SA_Oracle_Client);</STRONG></FONT></P>

	  <HR id=HR1>
	  <A name=Client></A>
      <H3>Client</H3><FONT face=Courier>
      <P><FONT face=Courier>/*<BR>  Queries current DBMS 
      client set by SAConnection::setClient or SAConnection::Connect.<BR>*/</FONT><FONT face=Courier></FONT></P>
      <P></FONT><FONT face=Courier>SAConnection Con;</FONT></P>
      <P><FONT face=Courier><FONT face=Courier>/* connect to database and so on 
      */<BR></FONT>...</FONT></P>
      <P><FONT face=Courier>switch(</FONT><FONT face=Courier><STRONG>Con.Client()</STRONG>)<BR></FONT><FONT face=Courier>{</FONT><FONT face=Courier><BR>&nbsp;&nbsp;&nbsp; case 
      SA_Client_NotSpecified:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      break;<BR>&nbsp;&nbsp;&nbsp; case 
      SA_ODBC_Client:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /*do smth. 
      specific for ODBC*/<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      break;<BR>&nbsp;&nbsp;&nbsp; case 
      SA_Oracle_Client:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /*do smth. 
      specific for Oracle*/<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      break;<BR>&nbsp;&nbsp;&nbsp; case 
      SA_SQLServer_Client:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /*do 
      smth. specific for 
      SQLServer*/<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      break;<BR>&nbsp;&nbsp;&nbsp; case 
      SA_Interbase_Client:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /*do 
      smth. specific for 
      Interbase*/<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      break;<BR>&nbsp;&nbsp;&nbsp; case 
      SA_SQLBase_Client:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /*do 
      smth. specific for SQLBase*/<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      break;<BR>&nbsp;&nbsp;&nbsp; case 
      SA_DB2_Client:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /*do smth. 
      specific for DB2*/<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      break;<BR>&nbsp;&nbsp;&nbsp; case 
      SA_Informix_Client:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /*do 
      smth. specific for 
      Informix*/<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      break;<BR>&nbsp;&nbsp;&nbsp; case 
      SA_Sybase_Client:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /*do smth. 
      specific for Sybase*/<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      break;</FONT><FONT face=Courier><BR>}</FONT></P>

	  <HR id=HR1>
	  <A name=ClientVersion></A>
      <H3>ClientVersion</H3>
      <P><FONT face=Courier>/*<BR>Query and print client version.<BR>     
      Exception handling is omitted for simplicity.<BR>*/</FONT><FONT face=Courier></FONT></P>
      <P><FONT face=Courier>SAConnection con;</FONT></P>
      <P><FONT 
      face=Courier>con.setClient(SA_Oracle_Client);</FONT></P>
      <P><FONT face=Courier>short minor = 
      (short)(<STRONG>con.ClientVersion() </STRONG>&amp; 0xFFFF);</FONT></P>
      <P><FONT face=Courier>short major = 
      (short)(<STRONG>con.ClientVersion() </STRONG>&gt;&gt; 16);</FONT></P>
      <P><FONT face=Courier>printf(&quot;Client version: 
      %hd.%hd\n&quot;, major, minor);</FONT></P>

	  <HR id=HR1>
	  <A name=ServerVersion></A>
      <H3>ServerVersion</H3>
      <P><FONT face=Courier>/*<BR>Query and print&nbsp;server version.<BR>     
      Exception handling is omitted for simplicity.<BR>*/</FONT><FONT face=Courier></FONT></P><FONT face=Courier>
      <P><FONT face=Courier>SAConnection con;</FONT></P>
      <P>con.Connect(&quot;dbname&quot;, &quot;username&quot;, &quot;password&quot;, 
      SA_Oracle_Client);</P>
      <P>short minor = (short)(<STRONG>con.ServerVersion() 
      </STRONG>&amp; 0xFFFF);</P>
      <P>short major = (short)(<STRONG>con.ServerVersion() 
      </STRONG>&gt;&gt; 16);</P>
      <P>printf(&quot;Server version: %hd.%hd\n&quot;, major, minor);</P>  </FONT>

	  <HR id=HR1>
	  <A name=ServerVersionString></A>
      <H3>ServerVersionString</H3><FONT face=Courier>
      <P><FONT face=Courier>/*<BR>Query and print&nbsp;server version 
      string.<BR>     
      Exception handling is omitted for simplicity.<BR>*/</FONT><FONT face=Courier></FONT></P><FONT face=Courier>
      <P><FONT face=Courier>SAConnection con;</FONT></P>
      <P>con.Connect(&quot;dbname&quot;, &quot;username&quot;, &quot;password&quot;, 
      SA_Oracle_Client);</P>
      <P>printf(&quot;Server: %s\n&quot;, (const 
      char*)<STRONG>con.ServerVersionString()</STRONG>);</P>
      <P>  </FONT></FONT>

	  <HR id=HR1>
	  <A name=isConnected></A>
      <H3>isConnected</H3><FONT face=Courier><FONT face=Courier>
      <P><FONT face=Courier>/*<BR>Disconnect only if we are really 
      connected.<BR>*/</FONT></P>
      <P><FONT face=Courier>SAConnection con;</FONT></P>
      <P><FONT face=Courier>/* connect to database and so on 
*/<BR>...</FONT></P>
      <P><FONT face=Courier>if(<STRONG>con.isConnected()</STRONG>)</FONT></P>
      <P><FONT face=Courier>&nbsp;&nbsp;&nbsp; con.Disconnect(); </FONT>
      <P>  </FONT></FONT>

      <HR id=HR1>
      <A name=Connect></A>
      <H3>Connect</H3>
      <P><FONT face=Courier>/*<BR> First example.<BR>Initialize client and 
      connect to server with one call.<BR>Exception handling is omitted for 
      simplicity.<BR>*/</FONT><FONT face=Courier></FONT></P>
      <P><FONT face=Courier>SAConnection con, con2;</FONT></P>
      <P><STRONG><FONT face=Courier>con.Connect(&quot;dbname&quot;, &quot;username&quot;, &quot;password&quot;, 
      SA_Oracle_Client);</FONT></STRONG></P>
      <P><FONT face=Courier><STRONG>con2.Connect(&quot;srvname@dbname&quot;, &quot;username&quot;, 
      &quot;password&quot;, SA_Sybase_Client);</STRONG>  
       </FONT></P>
      <P><FONT face=Courier>/*<BR>Second example.<BR>First initialize client 
      then connect to server.<BR>Exception handling is omitted for 
      simplicity.<BR>*/</FONT></P>
      <P><FONT face=Courier>SAConnection con, con2;</FONT></P>
      <P><FONT face=Courier>con.setClient(SA_Oracle_Client);</FONT></P>
      <P><FONT face=Courier>con2.setClient(SA_Sybase_Client);</FONT></P>
      <P><STRONG><FONT face=Courier>con.Connect(&quot;dbname&quot;, &quot;username&quot;, 
      &quot;password&quot;);</FONT></STRONG></P>
      <P><FONT face=Courier><STRONG>con2.Connect(&quot;srvname@dbname&quot;, &quot;username&quot;, 
      &quot;password&quot;);</STRONG>  
      </FONT></P>
      
      <HR id=HR1>
      <A name=Disconnect></A>
      <H3>Disconnect</H3>
      <P><FONT face=Courier>/*<BR> First 
      example.<BR>Disconnect only if we are really connected.<BR>*/</FONT></P>
      <P><FONT face=Courier>SAConnection con;</FONT></P>
      <P><FONT face=Courier>/* connect to database and so on 
      */<BR>...</FONT></P>
      <P><FONT face=Courier>if(con.isConnected())</FONT></P>
      <P><FONT face=Courier>&nbsp;&nbsp;&nbsp; 
      <STRONG>con.Disconnect();</STRONG> 
      </FONT></P>
      <P><FONT face=Courier>/*<BR>Second&nbsp;example.<BR>Disconnect is made 
      implicitly in destructor.<BR>*/</FONT></P>
      <P><FONT face=Courier>{</FONT></P>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -