·À·¶sql×¢Èë¹¥»÷£¨Ï£© ²ÎÊý»¯sql
ÉÏһƪдµÄsql×¢ÈëµÄ»ù±¾ÔÀí£¬±¾À´Òª½Ó×ÅдÕâÆªµÄ£¬µ«ÊÇÓÉÓÚʱ¼äµÄÔÒòһֱûÓÐд³É£¬½ñÌìÊÇÎåÒ»¼ÙÆÚ£¬×ÜËãÊÇÄܳé¿ÕддÁË¡£
×÷Ϊһ¸ö³ÌÐòÔ±£¬·À·¶sql×¢ÈëµÄµÚÒ»ÏßÊÇÓÉÎÒÃÇÀ´ÊØ»¤µÄ£¬Ö»ÒªÎÒÃÇÔÚ³ÌÐòÖÐÁôÉÙÐíµÄ©¶´£¬¾Í»á¸ø³ÌÐòÔöÇ¿°²È«ÌØÐÔ¡£ËùÒÔÎÒÃÇÒª×öµÄÊÇҪд°²È«µÄ³ÌÐò£¬·ÀÖ¹sql×¢ÈëÔÚ³ÌÐòÌåÏÖÔÚ²»ÒªÆ´½Ósql×Ö·û´®£¬Ò»¶¨Òª²ÎÊý»¯sql»òÕßд´æ´¢¹ý³Ì£¬ÕâÀï¾Í˵˵¼òµ¥µÄ²ÎÊý»¯sql°É¡£
Àý×ÓÖÐÓÃc#ºÍoracleʵÏÖ£¬javaÖлòÕ߯äËûÊý¾Ý¿âÖеÄʵÏÖÒ²ÊÇÀàËÆµÄ¡£
using System.Data.OracleClient;//ÒýÈëoracle²Ù×÷°ü
//¶¨ÒåDMLÓï¾ä
string strSQL = @"select user.name from user where user.name = :userName";
//ÉϾäÖеģºuserName¾ÍÊÇsqlÓï¾äÖвÎÊýµÄռλ·û£¬Ò²¾ÍÊÇ˵ÔÚÊý¾Ý¿â·þÎñÆ÷ÖÐÖ´ÐÐÕâÌõsqlÓï¾äµÄʱºòÕâ¸öռλ·ûÒª±»ÆäËû¶«Î÷Ìæ»»µô£¬µ½µ×ÓÃʲô¶«Î÷Ìæ»»ÄØ£¬½Ó×ÅÍùÏ¿´
OracleParameter[] param = {
new OracleParameter(":userName",txtName);
}//ÕâÀﶨÒåÒ»¸ö²ÎÊýµÄÊý×飬ÀïÃæ¿ÉÒÔдÈë¶à¸ösql²ÎÊý£¬ÔÛÃǵÄÕâÀïÖ»ÓÐÒ»¸ö£¬ËùÒÔ¾ÍдÈëÒ»¸ö²ÎÊý£¬ÕâÀイռλ·ûºÍËûµÄÌæ»»Ò²¾ÍÊDzÎÊýÖµ¶ÔÓ¦ÆðÀ´ÁË£¬txtName¾ÍÊÇռλ·ûµÄÌæ»»Öµ£¬ËûÊÇÓû§½çÃæÖÐÓû§ÊäÈëµÄÖµ£¬¾ÍÊÇËû¿ÉÄܺ¬ÓÐ×¢Èë¹¥»÷µÄ×Ö·û£¬ÕâÏÂÊý¾Ý¿â·þÎñÆ÷ÖªµÀÓÃʲô¶«Î÷Ìæ»»Õ¼Î»·ûÁË¡£
¶¨ÒåºÃsqlÓï¾äºÍ²ÎÊýºó¾ÍÊÇÖ´ÐÐÁË£¬Ö´ÐеÄʱºòÐèҪͬʱ½«sqlÓï¾äºÍ²ÎÊý´«È룬ÕâÑùÓû§ÊäÈëµÄ´øÓзǷ¨×Ö·ûµÄ×Ö·û´®ÔÚÊý¾Ý¿â»áµ±×÷²ÎÊý´¦Àí£¬¶ø²»»áµ±×÷sqlÓï¾äºÍÊý¾Ý¿â×Ô¼ºµÄ×Ö·û»ìÂÒ£¬·ÀÖ¹ÁË×¢Èë¹¥»÷¡£
OracleCommand cmd = new OracleCommand();
cmd.CommandText = strSQL;//¶¨ÒåoracleÃüÁîµÄÎı¾ÄÚÈÝ
for(oracleParameter p in param)//½«²ÎÊý´«Èë
{
cmd.Parameters.Add(p);
}
cmd.ExecuteNonQuery(); //Ö´ÐÐÃüÁî
ÉÏÃæ»ù±¾ÉÏÊÇÒ»¸öÍêÕûµÄ²ÎÊý»¯sql£¬²»Í¬µÄÊý¾Ý¿â·þÎñÆ÷sqlÓï¾äÖвÎÊýµÄռλ·û²»Í¬£¬ÉÏÃæÓõÄÊÇoracle£¬²ÎÊýռλ·ûÊÇðºÅ£¨£º£©¼ÓÃû×Ö£¬ÔÚsqlserverÖÐÊÇÓÃ@·ûºÅ¼ÓÃû×Ö×÷Ϊռλ·û£¬¶øÔÚmysqlÖÐÓÃÎʺţ¨£¿£©¼ÓÃû×ÖÀ´×÷Ϊ²ÎÊýռλ·û£¬²»Í¬µÄÊý¾Ý¿âÖвÎÊýµÄ±íʾ·ûºÅ²»Ò»Ñù£¬Õâ¸öÐèҪעÒâ¡£
Ïà¹ØÎĵµ£º
½ñÌìÔÚÒ»¸öVPSÉϰ²×°sql2005£¬°²×°ºÃºó±¾µØÒ»Ö±Á¬½Ó²»ÉÏ
¼ò½é
ÔÚ³¢ÊÔ´ÓÔ¶³Ì¼ÆËã»úÁ¬½Óµ½ Microsoft SQL Server 2005 ʵÀýʱ£¬¿ÉÄÜ»á½ÓÊÕµ½´íÎóÏûÏ¢¡£ÔÚʹÓÃÈκγÌÐòÁ¬½Óµ½ SQL Server ʱ¶¼¿ÉÄܻᷢÉú´ËÎÊÌâ¡£ÀýÈ磬ÔÚʹÓà SQLCMD ʵÓù¤¾ßÁ¬½Óµ½ SQL Server ʱÊÕµ½ÒÔÏ´íÎóÏûÏ¢£º
Sqlcmd:´íÎó:Microsoft SQL Native Cli ......
//tree.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Syst ......
¼Ü¹¹£¨Schema£©¡£Î¢ÈíµÄ¹Ù·½ËµÃ÷£¨MSDN£©£º
"Êý¾Ý¿â¼Ü¹¹ÊÇÒ»¸ö¶ÀÁ¢ÓÚÊý¾Ý¿âÓû§µÄ·ÇÖØ¸´ÃüÃû¿Õ¼ä£¬Äú¿ÉÒÔ½«¼Ü¹¹ÊÓΪ¶ÔÏóµÄÈÝÆ÷"£¬Ïêϸ²Î¿¼
http://technet.microsoft.com/zh-cn/library/ms190387.aspx.ÎÒÃÇÖªµÀ£¬ÔÚJAVAÖУ¬ÃüÃû¿Õ
¼äÃûÆäʵ¾ÍÊÇÎļþ¼ÐÃû¡£Òò´ËÎÒÃǷdz£Ã÷È·Ò»µã£ºÒ»¸ö¶ÔÏóÖ»ÄÜÊôÓÚÒ»¸ö¼Ü¹¹£¬¾ÍÏ ......
ÓеÄʱºòÎÒÃÇÐèÒªÒ»´ÎÏñÊý¾Ý¿âÖÐÌí¼Ó¶àÌõ¼Ç¼£¬ÎÒÃÇ¿ÉÒÔʹÓÃÏÂÃæµÄÓï¾äÀ´ÊµÏÖ£º
--Ìí¼ÓÒ»Ìõ¼Ç¼
INSERT INTO tableName(col1,col2,col3) VALUES (1,2,3)
--Ìí¼Ó¶àÌõ¼Ç¼
INSERT INTO tableName(col1,col2,col3)
SELECT 3,4,5
UNION ALL
SELECT 6,7,8
--´ÓÁíÍâµÄÒ»ÕűíÖжÁÈ¡¶àÌõÊý¾ÝÌí¼Óµ½Ð±íÖÐ
INSERT INTO tabl ......
ÏÂÃæÊDzÙ×÷²½Ö裺
1. “·þÎñºÍÁ¬½ÓµÄÍâΧӦÓÃÅäÖÓ -¡·“±¾µØÁ¬½ÓºÍÔ¶³ÌÁ¬½Ó”-¡·“ͬʱʹÓÃTCP/IPºÍNamed Pipes“£»
2. “·þÎñÅäÖùÜÀíÆ÷”-¡·“ÍøÂçÅäÖÔ-¡·“SQL ExpressµÄÐÒé“-¡·“IPµØÖ·”£¬½«IpAll Tcp¶Ë¿Ú¸ÄΪ1433£»
3. ÖØÆô·þ ......