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

📄 448.html

📁 关于jsp的一些好文章 主要介绍一些关于JSP的应用技巧方面的东西
💻 HTML
字号:

<STYLE type=text/css>
<!--
body,td { font-size:9pt;}
hr { color: #000000; height: 1px}
-->
</STYLE>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD><TITLE>FAQ汇萃 >> SQL之家 >> 如何在ASP中使用mySQL</title>
</head>
<body >

<p><IMG SRC="../image/jsp001_middle_logo.gif" WIDTH="180" HEIGHT="60" BORDER=0 ALT=""></p>

<table width=100% bgcolor="#cccccc" align=center cellpadding="2" cellspacing="0" border=1 bordercolorlight="#000000" bordercolordark="#FFFFFF">
<tr bgcolor="#EFF8FF"><td>
<a href=http://www.jsp001.com/list_thread.php?int_attribute=1>FAQ汇萃</a>
>> <a href=http://www.jsp001.com/list_thread.php?forumid=45&int_attribute=1>SQL之家</a>
>> 如何在ASP中使用mySQL [<a href=http://www.jsp001.com/forum/showthread.php?goto=newpost&threadid=448>查看别人的评论</a>]<br>

<hr><p>由 amtd 发布于: 2001-02-15 09:36</p><p> </p><p><br><br>Using A mySQL Databases<br>by Ben O'Neill <br><br><br>Databases are the best way to keep your web site up-to-date and dynamic. Databases are used these days by <br>thousands of web sites. They are used for storing news and general information. Web sites like the ASP <br>Index (www.aspin.com) are run on large databases. Databases make a web site easy to update and once you <br>have the base script, to add, remove and modify things in a database is very easy. <br><br> <br><br>To start you need to know how to connect to a database. ASP can connect to virtually any type, from <br>Microsoft Access to SQL. In this example I'll be using mySQL and OLE DB to connect to it. <br><br> <br><br>mySQL can be downloaded from the mySQL web site (www.mysql.com). You will also need the provider used to <br>connect to it, also available from the mySQL web site. <br><br> <br><br>You may be asking what's OLE DB? I'm used to ODBC and DSN. OLE DB is faster and more stable. It's almost <br>exactly the same. <br><br> <br><br>First we need to connect to the database, because it's a mySQL database you also need to supply a database <br>name. (in mySQL you can have mulitple databases on the same SQL server.) <br><br> <br><br>&lt;% <br><br>strConnection = "driver={MySQL};server=localhost;uid=benoneill;pwd=mypassword;database=databasename" <br><br> <br><br>Set adoDataConn = Server.CreateObject("ADODB.Connection") <br><br>adoDataConn.Open strConnection <br><br>%&gt; <br><br> <br><br>And now we've connected. Let's pretend we've got a big list of lots and lots of email addresses, here's <br>the contents of our database, it allows me to show you how it works better. <br><br> <br><br>Table Name: emailadds <br><br> <br><br>name牋牋牋牋牋牋牋?牋牋牋牋牋?emailadd <br><br>------------------------------------------------------ <br><br>Ben牋牋牋牋牋牋牋牋?牋牋牋牋牋?sheepcow@planetunreal.com <br><br>Fred牋牋牋牋牋牋牋牋 牋牋牋牋牋?freddy@thebigisp.com <br><br>Ben Harding牋牋 牋牋牋牋牋?benharding@hisisp.com <br><br>Dave Geralding 牋牋牋牋牋?daveg@mymail.com <br><br> <br><br>Now we have the database open let's run a query to list and output all the names and email address in a <br>nice easy to view table. <br><br> <br><br>&lt;% <br><br>?strQuery = "SELECT * FROM emailadds" <br><br> <br><br>?Set rsEmailData = adoDataConn.Execute(strQuery) <br><br> <br><br>?If Not rsEmailData.BOF Then <br><br>%&gt; <br><br> <br><br>&lt;TABLE&gt; <br><br> <br><br>?/span&gt;&lt;TR&gt;<br><br>牋 &lt;TD&lt;b&gt;Name&lt;/b&gt;&lt;/TD&gt;<br><br>牋 &lt;TD&gt;&lt;b&gt;Email Address&lt;/b&gt;&lt;/TD&gt;<br><br>?/span&gt;&lt;/TR&gt; <br><br> <br><br>&lt;% <br><br>?Do While Not rsEmailData.EOF <br><br>%&gt; <br><br> <br><br>?/span&gt;&lt;TR&gt;<br><br>牋 &lt;TD&gt;&lt;%=rsEmailData("name").Value %&gt;&lt;/TD&gt;<br><br>牋 &lt;TD&gt;&lt;%=rsEmailData("emailadd").Value %&gt;&lt;/TD&gt;<br><br>?/span&gt;&lt;/TR&gt; <br><br> <br><br>&lt;% <br><br>牋?rsEmailData.MoveNext <br><br>?Loop <br><br> <br><br>%&gt; <br><br> <br><br>&lt;/TABLE&gt; <br><br> <br><br>&lt;% <br><br>?Else <br><br> <br><br>牋? Response.Write("Sorry, no email addresses found.") <br><br> <br><br>?End If <br><br>%&gt; <br><br> <br><br> <br><br>There we go. If no records are found then it says "Sorry, no email addresses found". <br><br> <br><br>That query is simple enough, it tells the database to get (SELECT) all the records and all the fields from <br>the table named emailadds. <br><br> <br><br>How about we make it only show people with the name "ben" somewhere in their name, simple change the query <br>to this: <br><br> <br><br>SELECT * FROM emailadds WHERE name LIKE '%ben%' <br> <br><br>That query would return only 2 records, Ben and Ben Harding. <br><br> <br><br>It's important you use single quotes ('), because double quotes won't work. You can also be very selective <br>and do: <br><br> <br><br>SELECT * FROM emailadds WHERE name='Ben' <br> <br><br>That query would only return Ben, not Fred or Ben Harding, or Dave Geralding. <br><br> <br><br>After using databases you should always clear up. Close the database and the record set, and set them to <br>nothing so that the memory used by them is regained, do this by writing this: <br><br> <br><br>&lt;% <br><br>?rsEmailData.Close <br><br>?adoDataConn.Close <br><br> <br><br>?Set adoDataConn = Nothing <br><br>?Set rsEmailData = Nothing <br><br>%&gt;<br><br><br> <br><br>__________________<br><font color=red>真实源于生活! </font><br>请访问我们的网站: <br>(VB爱好者乐园) <br><a href="http://www.vbgood.com" target=_blank>http://www.vbgood.com</a><br><a href="http://www.d1vb.com" target=_blank>http://www.d1vb.com</a><br><a href="http://61.128.97.225/vbgood/index.asp" target=_blank>http://61.128.97.225/vbgood/index.asp</a><br>拥有1800多个资料! </p></td>
  </tr>
</table>

<p>
<CENTER><a href="http://www.jsp001.com/forum/newreply.php?action=newreply&threadid=448">点这里对该文章发表评论</a></CENTER>
<p>该文章总得分是 <font color=red>6</font> 分,你认为它对你有帮助吗?
				[<a href=javascript:void(0) onclick=window.open("http://www.jsp001.com/forum/codeVote.php?threadid=448&intVote=4","","menubar=no,toolbar=no,location=no,directories=no,status=no,resizable=no,scrollbars=no,width=70,height=40,top=0,left=0")>非常多</a>](<font color=red>1</font>) 
				[<a href=javascript:void(0) onclick=window.open("http://www.jsp001.com/forum/codeVote.php?threadid=448&intVote=2","","menubar=no,toolbar=no,location=no,directories=no,status=no,resizable=no,scrollbars=no,width=70,height=40,top=0,left=0")>有一些</a>](<font color=red>1</font>) 
				[<a href=javascript:void(0) onclick=window.open("http://www.jsp001.com/forum/codeVote.php?threadid=448&intVote=1","","menubar=no,toolbar=no,location=no,directories=no,status=no,resizable=no,scrollbars=no,width=70,height=40,top=0,left=0")>无帮助</a>](<font color=red>1</font>) 
				[<a href=javascript:void(0) onclick=window.open("http://www.jsp001.com/forum/codeVote.php?threadid=448&intVote=-1","","menubar=no,toolbar=no,location=no,directories=no,status=no,resizable=no,scrollbars=no,width=70,height=40,top=0,left=0")>是灌水</a>](<font color=red>1</font>) </p>
<script language="javascript" src="http://www.jsp001.com/include/read_thread_script.php?threadid=448"></script>
<p><CENTER>
Copyright &copy; 2001 - 2009 JSP001.com . All Rights Reserved <P>

<IMG SRC="../image/jsp001_small_logo.gif" WIDTH="85" HEIGHT="30" BORDER=0 ALT="">
</CENTER></p>

</body>
</html>

⌨️ 快捷键说明

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