60 lines
1.9 KiB
Text
60 lines
1.9 KiB
Text
/* NetRexx */
|
|
options replace format comments java crossref symbols binary
|
|
|
|
import java.sql.Connection
|
|
import java.sql.Statement
|
|
import java.sql.SQLException
|
|
import java.sql.DriverManager
|
|
|
|
class RTableCreate01 public
|
|
properties private constant
|
|
addressDDL = String '' -
|
|
' create table Address' -
|
|
' (' -
|
|
' addrID integer primary key generated by default as identity,' -
|
|
' addrStreet varchar(50) not null,' -
|
|
' addrCity varchar(50) not null,' -
|
|
' addrState char(2) not null,' -
|
|
' addrZip char(10) not null' -
|
|
' )'
|
|
driver = String 'org.apache.derby.jdbc.EmbeddedDriver'
|
|
dbName = String 'db/rosetta_code'
|
|
|
|
method createTable() public static
|
|
connectionURL = String
|
|
conn = java.sql.Connection
|
|
sqlStatement = java.sql.Statement
|
|
do
|
|
Class.forName(driver)
|
|
connectionURL = 'jdbc:derby:' || dbName || ';' || 'create=true'
|
|
conn = DriverManager.getConnection(connectionURL)
|
|
sqlStatement = conn.createStatement()
|
|
say 'Creating table'
|
|
sqlStatement.execute(addressDDL)
|
|
say 'Table creation complete'
|
|
sqlStatement.close()
|
|
conn.close()
|
|
do
|
|
-- In embedded mode, an application should shut down Derby.
|
|
-- Shutdown throws the XJ015 exception to confirm success.
|
|
connectionURL = 'jdbc:derby:' || ';' || 'shutdown=true'
|
|
DriverManager.getConnection(connectionURL)
|
|
catch sex = SQLException
|
|
if sex.getSQLState().equals("XJ015") then do
|
|
say 'Database shut down normally'
|
|
end
|
|
else do
|
|
say 'Database did not shut down normally'
|
|
signal sex
|
|
end
|
|
end
|
|
catch sex = SQLException
|
|
sex.printStackTrace()
|
|
catch ex = ClassNotFoundException
|
|
ex.printStackTrace()
|
|
end
|
|
return
|
|
|
|
method main(args = String[]) public static
|
|
createTable()
|
|
return
|