网站制作 静态的HTML文件已经做好了,怎么连接数据库

静态的HTML文件已经做好了,怎么连接数据库
就是有些图片框放产品图片用,access数据库文件弄好了,怎么连接起来?

access数据库一般用ASP,下面是示例代码:

asp连接access数据库应用下面代码
<%
set conn=Server.CreateObject("ADODB.Connection")
DBPath = Server.MapPath("board.mdb") 'Server.MapPath("board.mdb") 获得数据库文件board.mdb的绝对路径
conn.Open "provider=microsoft.jet.oledb.4.0;data source="&dbpath
%>
首先在board.mdb数据库里建立一张数据表board(id,title,content,subtime)个字段数据类型自己思考,环境都建好了,下面我们就开始程序设计,无论网页还是程序我建议用dw来做吧,我就是用它的
本例中涉及到的文件有
conn.asp数据库链接文件
send.asp,发表留言界面页
sendok.asp,留言录库操作程序文件
board.asp留言读库显示页面
文件的内容附件里有源文件大家可以下载察看
首先介绍asp一个很有效的特性就是服务器端包含
<!--#i nclude file="conn.asp"-->
其中conn.asp就是被包含的文件,此包含可以出现在文件的任意位置
被包含的文件内容将完全被解释成包含文件的内容,,重复的代码也会大大降低。

conn.asp内容
<%
set conn=Server.CreateObject("ADODB.Connection")
DBPath = Server.MapPath("board.mdb")
conn.Open "provider=microsoft.jet.oledb.4.0;data source="&dbpath
%>
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
send.asp内容
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; ch***t=gb2312">
<title>无标题文档</title>
<style type="text/css">
<!--
.style1 {font-size: 18px}
-->
</style>
</head>

<body>
<table width="700" border="0" align="center">
<form name="form1" method="post" action="sendok.asp">
<tr>
<td><div align="center" class="style1">发布留言</div></td>
</tr>
<tr>
<td align="center">标题:
<input name="title" type="text" size="50"></td>
</tr>
<tr>
<td align="center">内容:
<textarea name="content" cols="50"></textarea></td>
</tr>
<tr>
<td align="center"><input type="submit" name="Submit" value="提交"></td>
</tr>
</form>
</table>
</body>
</html>
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
sendok.asp内容
<!--#i nclude file="conn.asp"-->
<%
title=request.form("title")
content=request.form("content")
subtime=now()
conn.execute("insert into board (title,content,subtime) values('"&title&"','"&content&"','"&subtime&"')")
%>
<script>
alert("留言成功!");
location.href="/board.asp";
</script>
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
board.asp内容
<!--#i nclude file="conn.asp"-->

<style type="text/css">
<!--
.style2 {
font-size: 16px;
font-weight: bold;
}
-->
</style>
<table width="300" border="0" align="center">
<tr>
<td align="center"><span class="style2">留言板查看</span></td>
</tr>
</table>
<br>
<br>
<table width="200" border="0" align="center">
<tr>
<td align="center"><a href="/send.asp">发表留言</a></td>
</tr>
</table>
<br>
<br>
<%
set rs=conn.execute("select * from board order by id desc")
do while not rs.eof
%>
<table width="600" border="0" align="center" cellspacing="1" bgcolor="#999999">
<tr bgcolor="#FFFFFF">
<td width="447"><%=rs("title")%></td>
<td width="146"><%=rs("subtime")%></td>
</tr>
<tr bgcolor="#FFFFFF">
<td colspan="2"><%=rs("content")%></td>
</tr>
<tr bgcolor="#FFFFFF">
<td colspan="2"> </td>
</tr>
</table>
<%
rs.movenext
loop
rs.close
set rs=nothing
conn.close
set conn=nothing

%>
温馨提示:内容为网友见解,仅供参考
第1个回答  2009-09-01
把所有要加数据库内容的页面的后缀都改为(asp\php\aspx\jsp)是的一种就行,看你会什么了,呵呵!之后就可以加入服务器脚本语言了。就这么简单本回答被提问者采纳
第2个回答  2015-07-03
1.通常来说web应用还是用java来连接数据库,java 连接数据库底层只有一种方式就是jdbc,像hibernate或者mybatis框架都是对jdbc的封装
第3个回答  2015-06-14
你需要一门后台语言。。比如PHP,
相似回答