mn8 Language Reference | Index    

JDBCConnection

SUMMARY: NO ATTRIBUTES  NO ELEMENTS  NO CONSTRUCTORS  NO OPERATORS  METHODS SUMMARYDETAIL: NO ATTRIBUTES  NO ELEMENTS  NO CONSTRUCTORS  NO OPERATORS  METHOD DETAILS

Description

A connection (session) with a specific database. Within this concept, SQL statements are executed and results are returned.

Note: By default the JDBCConnection automatically commits changes after executing each statement. If auto commit has been disabled, the method commit must be called explicitly; otherwise, database changes will not be saved.

Usage

Establish the database connection.

            $param typeof Map                                                                                                       
            $param.add("className", "org.postgresql.Driver")                                                                        
            $param.add("url", "jdbc:postgresql:testdb")                                                                             
            $param.add("user", "root")                                                                                              
            $param.add("passwd", "")                                                                                                
            $con  = JDBCClient.getConnection( $param )

Create the JDBCStatement for sending SQL statements to the database.

            $stmt = $con.createStatement

Set and get autoCommit modes. AutoCommit is default true .

            print $con.getAutoCommit
            #now autoCommit is false

            $con.setAtuoCommit( false )

            #If you want to commit an SQL statement you can use
            $con.commit

            #if you want to drops all changes made since the previous commit use
            $con.rollback 

Enable database optimizations for read-only connections.

            $con.setReadOnly(true)

Version: 0.1
Authors:Szabo Csaba ()
Location:
Inherits: Concept

Method List

close
commit
JDBCStatementcreateStatement
JDBCStatementcreateStatement (String $resultSetType, String $resultSetConcurrency)
LogicalgetAutoCommit
LogicalisClosed
LogicalisReadOnly
rollback
setAutoCommit (Logical $flag)
setReadOnly (Logical $flag)
top
Methods inherited from: Concept
cloneConcept, extendsConcept, fromXML, getAllInheritedConcepts, getConceptAttribute, getConceptAttributeField, getConceptAttributeFields, getConceptAttributes, getConceptConstructors, getConceptElement, getConceptElementField, getConceptElementFields, getConceptElements, getConceptLabel, getConceptMethod, getConceptMethods, getConceptOperators, getConceptType, getErrorHandler, getInheritedConcepts, getResourceURI, hasConceptAttribute, hasConceptElement, hasConceptMethod, hasPath, isHidden, loadContent, setConceptLabel, setErrorHandler, setHidden, setShowEmpty, showEmpty, toTXT, toXML, setResourceURI

Detailed Method Info

close
Returns:
Exceptions:
SQLException :
(Error)
if a database access error occurs.

Releases a JDBCConnection's database and JDBC resources immediately, instead of waiting for them to be automatically released.

                $param typeof Map                                                                                                       
                $param.add("className", "org.postgresql.Driver")                                                                        
                $param.add("url", "jdbc:postgresql:testdb")                                                                             
                $param.add("user", "root")                                                                                              
                $param.add("passwd", "")                                                                                                
                $con = JDBCClient.getConnection( $param )
                print $con.isClosed

                $con.close

                print $con.isClosed
                -- the result is --
                false
                true  
            

top
commit
Returns:
Exceptions:
SQLException :
(Error)
if a database access error occurs.

Makes all changes made since the previous commit/rollback permanent and releases any database locks currently held by the JDBCConnection. This method should be used only when auto-commit mode has been disabled.

                $param typeof Map                                                               
                $param.add("className", "org.postgresql.Driver")                                
                $param.add("url", "jdbc:postgresql:testdb")                                     
                $param.add("user", "root")                                                      
                $param.add("passwd", "")                                                        
                $con = JDBCClient.getConnection( $param )                                       
                $con.setAutocommit(false)                                                       
                $stmt = $con.createStatement
                $rs = $stmt.executeQuery("SELECT * FROM booleantb")                             
                $rs.setLast                                                                     
                $recNo = $rs.getRow                                                             
                $rs.close
                $stmt.executeUpdate("INSERT INTO booleantb VALUES(true)")                       

                $con.commit                                                                     

                $rs = $stmt.executeQuery("SELECT * FROM booleantb")                             
                $rs.setLast
                print "New record added : " + ( $rs.getRow != $recNo )                                                                     
                $rs.close                                                                       
                $stmt.close                                                                     
                $con.close 
                -- the result is --
                New record added : true
            

top
createStatement
Returns: JDBCStatement
Exceptions:
SQLException :
(Error)
if a database access error occurs.

Creates a JDBCStatement concept for sending SQL statements to the database. SQL statements without parameters are normally executed using JDBCStatement concept.

                $param typeof Map                                                               
                $param.add("className", "org.postgresql.Driver")                                
                $param.add("url", "jdbc:postgresql:testdb")                                     
                $param.add("user", "root")                                                      
                $param.add("passwd", "")                                                        
                $con = JDBCClient.getConnection( $param )

                $stmt = $con.createStatement

                print $stmt.getConceptType 
                $stmt.close                                                                     
                $con.close
                -- the result is --
                JDBCStatement
            

top
createStatement (String $resultSetType, String $resultSetConcurrency)
Parameters:
$resultSetType :a result set type: FORWARD , INSENSITIVE or SENSITIVE .
$resultSetConcurrency :a concurrency type: READ_OLNY or UPDATABLE
Returns: JDBCStatement
Exceptions:
SQLException :
(Error)
if a database access error occurs.

Creates a JDBCStatement concept that will generate JDBCResultSet concepts with the given type and concurrency. This method is the same as the createStatement method above, but it allows the default result set type and result set concurrency type to be overridden.

                $param typeof Map
                $param.add("className", "org.postgresql.Driver")
                $param.add("url", "jdbc:postgresql:testdb")
                $param.add("user", "root")
                $param.add("passwd", "")
                $con = JDBCClient.getConnection( $param )

                $stmt = $con.createStatement("FORWARD", "READ_ONLY")

                print $stmt.getConceptType 
                $stmt.close
                $con.close
                -- the result is --
                JDBCStatement
            

top
getAutoCommit
Returns: Logical
Exceptions:
SQLException :
(Error)
if a database access error occurs.

Gets the current auto-commit state.

                $param typeof Map
                $param.add("className", "org.postgresql.Driver")
                $param.add("url", "jdbc:postgresql:testdb")
                $param.add("user", "root")
                $param.add("passwd", "")
                $con = JDBCClient.getConnection( $param )

                print $con.getAutoCommit

                $con.close
                -- the result is --
                true
            

top
isClosed
Returns: Logical
Exceptions:
SQLException :
(Error)
if a database access error occurs.

Tests to see if a JDBCConnection is closed.

                $param typeof Map
                $param.add("className", "org.postgresql.Driver")
                $param.add("url", "jdbc:postgresql:testdb")
                $param.add("user", "root")
                $param.add("passwd", "")
                $con = JDBCClient.getConnection( $param )

                print $con.isClosed

                $con.close
                -- the result is --
                false
            

top
isReadOnly
Returns: Logical
Exceptions:
SQLException :
(Error)
if a database access error occurs.

Tests to see if the connection is in read-only mode.

                $param typeof Map
                $param.add("className", "org.postgresql.Driver")
                $param.add("url", "jdbc:postgresql:testdb")
                $param.add("user", "root")
                $param.add("passwd", "")
                $con = JDBCClient.getConnection( $param )

                print $con.isReadOnly                                                    

                $con.close
                -- the result is --
                false
            

top
rollback
Returns:
Exceptions:
SQLException :
(Error)
if a database access error occurs.

Drops all changes made since the previous commit/rollback and releases any database locks currently held by this JDBCConnection. This method should be used only when auto-commit has been disabled.

                $param typeof Map
                $param.add("className", "org.postgresql.Driver")
                $param.add("url", "jdbc:postgresql:testdb")
                $param.add("user", "root")
                $param.add("passwd", "")
                $con = JDBCClient.getConnection( $param )
                $con.setAutocommit(false)
                $stmt = $con.createStatement
                $rs = $stmt.executeQuery("SELECT * FROM booleantb")
                $rs.setLast
                $recNo = $rs.getRow
                $rs.close
                $stmt.executeUpdate("INSERT INTO booleantb VALUES(true)")

                $con.rollback 

                $rs = $stmt.executeQuery("SELECT * FROM booleantb")
                $rs.setLast
                print "New record added : " + ( $rs.getRow != $recNo )
                $rs.close
                $stmt.close
                $con.close
                -- the result is --
                New record added : false
            

top
setAutoCommit (Logical $flag)
Parameters:
$flag : True enables auto-commit; false disables auto-commit.
Returns:
Exceptions:
SQLException :
(Error)
if a database access error occurs.

Sets this connection's auto-commit mode. If a connection is in auto-commit mode, then all its SQL statements will be executed and committed as individual transactions. Otherwise, its SQL statements are grouped into transactions that are terminated by a call to either the method commit or the method rollback. By default, new connections are in auto-commit mode. The commit occurs when the statement completes or the next execute occurs, whichever comes first. In the case of statements returning a JDBCResultSet, the statement completes when the last row of the JDBCResultSet has been retrieved or the JDBCResultSet has been closed. In advanced cases, a single statement may return multiple results as well as output parameter values. In these cases the commit occurs when all results and output parameter values have been retrieved.

                $param typeof Map
                $param.add("className", "org.postgresql.Driver")
                $param.add("url", "jdbc:postgresql:testdb")
                $param.add("user", "root")
                $param.add("passwd", "")
                $con = JDBCClient.getConnection( $param )

                $con.setAutocommit( false )                                                       

                print "AutoCommit is : " + $con.getAutoCommit
                $con.close
                -- the result is --
                AutoCommit is : false
            

top
setReadOnly (Logical $flag)
Parameters:
$flag : true enables read-only mode; false disables read-only mode.
Returns:
Exceptions:
SQLException :
(Error)
if a database access error occurs.

Puts this connection in read-only mode as a hint to enable database optimizations.Note: This method cannot be called while in the middle of a transaction.

                $param typeof Map
                $param.add("className", "org.postgresql.Driver")
                $param.add("url", "jdbc:postgresql:testdb")
                $param.add("user", "root")
                $param.add("passwd", "")
                $con = JDBCClient.getConnection( $param )

                $con.setReadOnly( true )

                print "Is read-only: " + $con.isReadOnly
                $con.close
                -- the result is --
                Is read-only: true
            

top