Working with a SQL Derby database (creating a table)
Code: "io_derby_write.py". Programming language: Python DMelt Version 1. Last modified: 07/08/2015. License: Pro
https://datamelt.org/code/cache/io_derby_write_5779.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=true'
conn = DriverManager.getConnection(scon, props)
s = conn.createStatement()

try:
  s.execute('drop table '+table) 
except SQLException:
  print 'no need to remove table'

s.execute('create table '+table+'(num int, addr varchar(40))')
s.execute('insert into '+table+' values (1956,\'Webster St.\')')
s.execute('insert into '+table+' values (1910,\'Union St.\')')


s1='update '+table+' set num=?, addr=? where num=?'
ps = conn.prepareStatement(s1)
ps.setInt(1,180)
ps.setString(2, 'Grand Ave.')
ps.setInt(3, 1956)
ps.executeUpdate()
print 'Updated 1956 Webster to 180 Grand'


s.close()
conn.commit()

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

Ads help maintain this website.