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.
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)
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 |
|
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
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
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
Parameters: |
$resultSetType : | a result set type: FORWARD
, INSENSITIVE
or SENSITIVE
. |
$resultSetConcurrency : | a concurrency type: READ_OLNY
or UPDATABLE
|
|
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
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
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
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
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
Parameters: |
$flag : |
True
enables auto-commit; false
disables auto-commit. |
|
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
Parameters: |
$flag : |
true
enables read-only mode; false
disables read-only mode. |
|
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