选择显示字体大小

利用jsp的思想来做asp

这几天开始接触jsp里面一些bean的写法,然后自己想了想,认为其实在asp里面也可以采取这一思想来做。虽然不是很纯,不彻底,但是能够把一些逻辑处理分离出来,更适合程序的移植性,提高了开发周期。我自己写了个类connex包含了一些对数据库的操作,觉得应该可以包括一大部分的逻辑处理,但是这样也提高了错误几率,如果你把sql语句控制的比较好的话,应该是利大于弊的,这里都是一点点拙见,望大家指正。

程序的功能有了个大体的框架,其实可以自己添加一些功能,比如开始的数据库连接 ,可以先设置变量然后通过init() 来选择不同类型的数据库

<%
'*******************************************************************************************
'* 程序:connex.asp
'*
'* 描述:模仿javabean写的一个类,专门操作数据库,提供多种方法操作,但要避免sql语法错误!
'*
'* 作者:田野 email:foxty@sina.com
'*
'* 日期:2005.06.0
'*******************************************************************************************

'on error resume next
class connex
public connex
public dbpath '---------数据库路径
public dbtype '---------数据库类型 1(access) 2(sqlserver) 3(可扩充)
public connmethod '--------连接方式 (dsn,非dsn)
public user
public pass
sub class_initialize
end sub

sub init()
connstr = "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("date.mdb")
set connex = server.createobject("adodb.connection")
connex.open connstr
catcherror("class_terminate")
end sub

sub catcherror( str )
if err then
err.clear
class_terminate()
response.write("捕捉到错误,程序结束!在"&str&"处")
response.end()
end if
end sub

'******************************************
'*通过sql语句来查找记录是否存在,容易出错
'******************************************

function hasrecordbysql( sql )
call checksql(sql,"r")
dim rs,hasr
set rs = connex.execute( sql )
catcherror("hasreordsql")
if not (rs.eof or rs.bof) then
hasr = false
else
hasr = true
end if
rs.close
set rs = nothing
hasrecordbysql = hasr
end function

'***************************************
'*通过id来查找记录是否存在
'***************************************

function hasrecordbyid( strtablename , intid )
'checkvalue( intid , 1 )
dim rs,hasr
sql = "select top 1 * from "&strtablename&" where id = "&intid
call checksql(sql,"r")
set rs = connex.execute(sql)
catcherror("hasrecordbyid")
if not (rs.eof or rs.bof) then
hasr = false
else
hasr = true
end if
rs.close
set rs = nothing
hasrecordbyid = hasr
end function

'**********************************************
'*通过sql语句取得记录集
'**********************************************
function getrsbysql( sql )
call checksql(sql,"r")
dim rs
set rs = server.createobject("adodb.recordset")
rs.open sql,connex,1,1
set getrsbysql = rs
end function

'*********************************************
'*取得某个字段的值
'*********************************************
function getvaluebysql( sql )
call checksql(sql,"r")
dim rs,returnvalue
set rs = connex.execute(sql)
catcherror("getvaluebysql")
if not( rs.eof or rs.bof ) then
returnvalue = rs(0)
else
returnvalue = "没有记录"
end if
rs.close
set rs = nothing
getvaluebysql = returnvalue
end function

'==================================================update,insert==================================================================

'*********************************************
'*利用sql修改数据
'*********************************************
function updatebysql( sql )
call checksql(sql,"w")
connex.execute(sql)
catcherror("updatebysql")
updatebysql = true
end function

'********************************************
'*利用sql语句插入数据
'********************************************
function insertbysql(sql)
call checksql(sql,"w")
connex.execute(sql)
catcherror("insertbysql")
insertbysql = true
end function

'======================================================delete=============================================================

'********************************************
'*通过sql语句删除
'********************************************
function deletebysql( sql )
call checksql(sql,"d")
connex.execute(sql)
catcherror("deletebysql")
deletebysql = true
end function

'********************************************
'*检查sql语句权限,根据标志flag 来检测语句拥有的权限
'********************************************
sub checksql( sql , flag )
dim strsql,sincounts,doucounts,i
strsql = lcase(sql)
sincounts = 0
doucounts = 0
for i = 1 to len(strsql)
if mid(strsql,i,1) = "'" then sincounts = sincounts + 1
if mid(strsql,i,1) = """" then douconnts = doucounts + 1
next

if (sincounts mod 2) <> 0 or (doucounts mod 2) <> 0 or instr(strsql,";") > 0 then
call class_terminate()
response.write("sql语法错误!")
response.end()
end if
select case flag
case "r","r":
if instr(strsql,"delete") > 0 or instr(strsql,"update") or instr(strsql,"drop") > 0 or instr(strsql,"insert") > 0 then
class_terminate()
response.write("权限不足,没有执行写操作的权限")
response.end()
end if
case "w","w":
if instr(strsql,"delete") > 0 or instr(strsql,"drop") > 0 or instr(strsql,"select") > 0 then
class_terminate()
response.write("权限不足,没有执行删除操作的权限")
response.end()
end if
case "d","d":
case else:
response.write("函数checksql标志错误!")
end select
end sub

sub class_terminate
if not isempty(friendconn) then
friendconn.close
set friendconn = nothing
catcherror()
end if
end sub
end class
%>


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons