Working with a SQL database (reading using Derby)
Code: "io_derby_read.py". Programming language: Python DMelt Version 1. Last modified: 07/08/2015. License: Pro
https://datamelt.org/code/cache/io_derby_read_4014.py
To run this script using the DMelt IDE, copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.



from openDB import *

scon=protocol+dbName+';create=false'
conn = DriverManager.getConnection(scon,props)
s = conn.createStatement()

s1='SELECT num, addr FROM '+table+' ORDER BY num'
rs = s.executeQuery(s1)
while rs.next():
  print 'sorted='+rs.getString(1),rs.getString(2)
     
s2 = 'SELECT * FROM '+table+' WHERE addr=\'Union St.\''
rs = s.executeQuery(s2)
while rs.next():
  print 'Found=',rs.getString(1),rs.getString(2)

s.close()
conn.commit()

try:
 DriverManager.getConnection('jdbc:derby:;shutdown=true')
except SQLException:
 print 'all done'

Ads help maintain this website.