] > sample Jhyton program <..jython-sql.py..>
 #!/usr/bin/env jython
 
 """
     Sample jython program to test jdbc api
     Class:  CSE 670
     Author: Rick Holbert
     Date:   12 Nov 2004
 """
 from java.lang import *
 from java.sql import *
 from sys import *
 
 def get_connection(user, passwd):
     server   = ’database’
     port     = ’4101’
     database = ’c670ab’
     url = ’jdbc:sybase:Tds:’ + server + ’:’ + port + ’/’ + database
     Class.forName(’com.sybase.jdbc2.jdbc.SybDriver’).newInstance()
 
     try:
         conn = DriverManager.getConnection(url, user, passwd)
     except:
         print("connection error")
         exit(1)
     return conn
 
 # main part of program starts here
 
 if len(argv) == 3:
     username = argv[1]
     password = argv[2]
     conn = get_connection(username, password)
 else:
     print "Usage %s username password\n" % argv[0]
     exit(0)
 
 stmt = conn.createStatement()
 
 # stmt.executeUpdate( "use c670ab" )
 
 stmt.executeUpdate( "CREATE TABLE DBupdate (Name CHAR(10))" )
 
 stmt.executeUpdate( "INSERT INTO DBupdate VALUES ( ’my name’)" )
 
 stmt.executeUpdate( "INSERT INTO DBupdate VALUES ( ’your name’)" )
 
 result = stmt.executeQuery( "SELECT * FROM DBupdate" )
 
 while result.next():
     print ’Name:’, result.getString(1)
 
 stmt.executeUpdate( "DROP TABLE DBupdate" )
 
 result.close()
 stmt.close()
 conn.close()
 -_-_-

To test the Jython program you’ll need the following.