Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register

Versions available for this page: CUBRID 8.2.1 |  CUBRID 8.3.0 |  CUBRID 8.3.1 |  CUBRID 8.4.0 |  CUBRID 8.4.1 | 



ASP Sample

In the virtual directory where the ASP sample program runs, right-click "Default Web Site" and click [Properties].

gs_app_odbc_asp_website.png

The dialog box shown above will appear. Under the Web Site Identification, in the IP Address drop-down box, select "(All Unassigned)." This sets the IP address to localhost. If you want to run the sample program using a specific IP address, configure the directory with the IP address as a virtual directory and register the IP address in Properties.

The following example shows how to configure IP address as localhost.

Example

The following example shows how to create cubrid.asp and store it into a virtual directory.

<HTML>

    <HEAD>

     <meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">

       <title>CUBRID Query Test Page</title>

  </HEAD>

 <BODY topmargin="0" leftmargin="0">

   

 <table border="0" width="748" cellspacing="0" cellpadding="0">

   <tr>

     <td width="200"></td>

     <td width="287">

       <p align="center"><font size="3" face="Times New Roman"><b><font color="#FF0000">CUBRID</font>Query Test</b></font></td>

     <td width="200"></td>

   </tr>

 </table>

 <form action="cubrid.asp" method="post" >

 <table border="1" width="700" cellspacing="0" cellpadding="0" height="45">

   <tr>

     <td width="113" valign="bottom" height="16" bgcolor="#DBD7BD" bordercolorlight="#FFFFCC"><font size="2">SERVER IP</font></td>

     <td width="78"  valign="bottom" height="16" bgcolor="#DBD7BD" bordercolorlight="#FFFFCC"><font size="2">Broker PORT</font></td>

     <td width="148" valign="bottom" height="16" bgcolor="#DBD7BD" bordercolorlight="#FFFFCC"><font size="2">DB NAME</font></td>

     <td width="113" valign="bottom" height="16" bgcolor="#DBD7BD" bordercolorlight="#FFFFCC"><font size="2">DB USER</font></td>

     <td width="113" valign="bottom" height="16" bgcolor="#DBD7BD" bordercolorlight="#FFFFCC"><font size="2">DB PASS</font></td>

     <td width="80" height="37" rowspan="4" bordercolorlight="#FFFFCC" bgcolor="#F5F5ED">

       <p><input type="submit" value="Execute" name="B1" tabindex="7"></p></td>

   </tr>

   <tr>

     <td width="113" height="1" bordercolorlight="#FFFFCC" bgcolor="#F5F5ED"><font size="2"><input type="text" name="server_ip" size="20" tabindex="1" maxlength="15" value="<%=Request("server_ip")%>"></font></td>

     <td width="78"  height="1" bordercolorlight="#FFFFCC" bgcolor="#F5F5ED"><font size="2"><input type="text" name="cas_port" size="15" tabindex="2" maxlength="6" value="<%=Request("cas_port")%>"></font></td>

     <td width="148" height="1" bordercolorlight="#FFFFCC" bgcolor="#F5F5ED"><font size="2"><input type="text" name="db_name" size="20" tabindex="3" maxlength="20" value="<%=Request("db_name")%>"></font></td>

     <td width="113" height="1" bordercolorlight="#FFFFCC" bgcolor="#F5F5ED"><font size="2"><input type="text" name="db_user" size="15" tabindex="4" value="<%=Request("db_user")%>"></font></td>

     <td width="113" height="1" bordercolorlight="#FFFFCC" bgcolor="#F5F5ED"><font size="2"><input type="password" name="db_pass" size="15" tabindex="5" value="<%=Request("db_pass")%>"></font></td>

   </tr>

   <tr>

     <td width="573" colspan="5" valign="bottom" height="18" bordercolorlight="#FFFFCC" bgcolor="#DBD7BD"><font size="2">QUERY</font></td>

   </tr>

   <tr>

     <td width="573" colspan="5" height="25" bordercolorlight="#FFFFCC" bgcolor="#F5F5ED"><textarea rows="3" name="query" cols="92" tabindex="6"><%=Request("query")%></textarea></td>

   </tr>

 </table>

 </form>

 <hr>

</BODY>

</HTML>

<%

    ' Fetch the DSN and SQL statement.

    strIP = Request( "server_ip" )

    strPort = Request( "cas_port" )

    strUser = Request( "db_user" )

    strPass = Request( "db_pass" )

    strName = Request( "db_name" )

    strQuery = Request( "query" )

   

if strIP = "" then

   Response.Write "Please enter the SERVER_IP"

        Response.End 'If no IP entered, end the page

    end if

    if strPort = "" then

       Response.Write "Please enter the port number"

        Response.End ' If no port entered, end the page

    end if

    if strUser = "" then

       Response.Write "Please enter the DB_USER"

        Response.End ' If no DB_User entered, end the page

    end if

    if strName = "" then

       Response.Write "Please enter the DB_NAME "

        Response.End ' If no DB_NAME entered, end the page

    end if

    if strQuery = "" then

       Response.Write "Please enter the query you want to check"

        Response.End ' If no Query entered, end the page

    end if

 ' Create the connection object

  strDsn = "driver={CUBRID Driver};server=" & strIP & ";port=" & strPort & ";uid=" & strUser & ";pwd=" & strPass & ";db_name=" & strName & ";"

' Connect to DB

Set DBConn = Server.CreateObject("ADODB.Connection")

       DBConn.Open strDsn

    ' Execute SQL

    Set rs = DBConn.Execute( strQuery )

    ' Show message depending on the SQL statement

    if InStr(Ucase(strQuery),"INSERT")>0 then

        Response.Write "The record has been added."

        Response.End

    end if

       

    if InStr(Ucase(strQuery),"DELETE")>0  then

        Response.Write "The record has been deleted."

        Response.End

    end if

       

    if InStr(Ucase(strQuery),"UPDATE")>0  then

        Response.Write "The record has been modified."

        Response.End

    end if   

%>

<table>

<%   

    ' Show the field name

    Response.Write "<tr bgColor=#f3f3f3>"

    For index =0 to ( rs.fields.count-1 )

        Response.Write "<td><b>" & rs.fields(index).name & "</b></td>"

    Next

    Response.Write "</tr>"

    ' Show the field value

    Do While Not rs.EOF

        Response.Write "<tr bgColor=#f3f3f3>"

        For index =0 to ( rs.fields.count-1 )

            Response.Write "<td>" & rs(index) & "</td>"

        Next

        Response.Write "</tr>"

              

        rs.MoveNext

    Loop

%>

<% 

    set  rs = nothing

%>

</table>

You can check the result of the sample program at http://localhost/aSP/cubrid.asp. When you execute the sample code above, you will get the following output. Enter appropriate values in each field, and then enter the query statement in the Query field. When you click [Run], the query result will be displayed at the lower portion of the page.

gs_app_odbc_asp_querytest.png