ADOSample.py :  » Web-Frameworks » Webware » Webware-1.0.2 » COMKit » Examples » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Web Frameworks » Webware 
Webware » Webware 1.0.2 » COMKit » Examples » ADOSample.py
# ADOSample.py
#
# Simple example of using ADO in WebKit for database access with
# automatic connection pooling.
#
# To run this example, you'll have to set EnableCOM to 1 in the
# AppServer.config file; you'll have to create a database with a table
# called Customers that has a CustomerName field; and you'll
# have to create a System DSN called MyDataSource that points to
# that database.  Then, install this file in the WebKit/Examples
# directory and try it out.  It ought to work with any database
# accessible through ODBC and/or ADO.
#
# The recordset function below should go into a base class so it
# can be shared among many servlets.

from win32com.client import Dispatch
from ExamplePage import ExamplePage


class ADOSample(ExamplePage):

  def recordset(self, sql):
    # Open an ADO connection
    conn = Dispatch('ADODB.Connection')
    conn.Open('MyDataSource')
    # Store the connection in the Application object.  We're never going to
    # USE this stored connection, but we're saving it so that we'll always
    # have at least one connection to this data source open.  ADO
    # will automatically pool connections to a given data source as long as
    # at least one connection to that data source remains open at all times,
    # so doing this significantly increases the speed of opening
    # the connection the next time this function is called.
    self.application().MyDataSource_connection = conn
    # Open and return the requested recordset
    rs = Dispatch('ADODB.Recordset')
    rs.Open(sql, conn)
    return rs

  def writeContent(self):
    # Grab some data from the database and display it
    rs = self.recordset('SELECT CustomerName FROM Customers ORDER BY CustomerName')
    self.writeln('<h1>ADO Sample</h1>')
    self.writeln('<h3>Your Customers are:</h3>')
    self.writeln('<ul>')
    while not rs.EOF:
      self.writeln('<li>%s</li>' % rs.Fields('CustomerName').Value)
      rs.MoveNext()
    self.writeln('</ul>')
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.