- See Also:
- Top Examples, Source Code,
DriverManager.getConnection(java.lang.String, java.util.Properties)
,
Statement
,
ResultSet
,
DatabaseMetaData
void clearWarnings()
throws SQLException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
void close()
throws SQLException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[294]Create SQL statement
By Anonymous on 2004/10/08 13:09:19 Rate
public ResultSet query ( String sql_query ) throws SQLException {
Connection con = myUtil.getDBConnection ( ) ;
Statement stmt = con.createStatement ( ) ;
ResultSet rs = stmt.executeQuery ( sql_query ) ;
try
{
stmt.close ( ) ;
stmt = null;
myUtil.closeDBConnection ( ) ;
con = null;
} catch ( SQLException se ) { }
return rs;
}
void commit()
throws SQLException
- See Also:
setAutoCommit(boolean)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
Statement createStatement()
throws SQLException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[671]Create database table programmatically
By Anonymous on 2005/05/21 22:30:04 Rate
String dbUrl = "jdbc:mysql://localhost/kickjava";
String jdbcDriver = "com.mysql.jdbc.Driver";
Connection con = null;
Statement stmt = null;
String sqlCmd = "CREATE TABLE BLOBS ( " +
"ID INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, " +
"FILENAME VARCHAR ( 255 ) NOT NULL, " +
"BINARYDATA BLOB NOT NULL ) ;";
try {
Class.forName ( jdbcDriver ) ;
con = DriverManager.getConnection ( dbUrl ) ;
stmt = con.createStatement ( ) ;
stmt.execute ( sqlCmd ) ;
}
catch ( ClassNotFoundException e ) {
System.err.println ( e ) ;
}
catch ( SQLException e ) {
System.err.println ( e ) ;
}
finally {
try {
stmt.close ( ) ;
con.close ( ) ;
} catch ( SQLException e ) {
System.err.println ( e ) ;
}
stmt = null;
con = null;
}
Statement createStatement(int resultSetType,
int resultSetConcurrency)
throws SQLException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
Statement createStatement(int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
throws SQLException
- See Also:
ResultSet
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
boolean getAutoCommit()
throws SQLException
- See Also:
setAutoCommit(boolean)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
String getCatalog()
throws SQLException
- See Also:
setCatalog(java.lang.String)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
int getHoldability()
throws SQLException
- See Also:
ResultSet
, setHoldability(int)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
DatabaseMetaData getMetaData()
throws SQLException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[1497]Get database metadata
By hellohiren { at } gawab { dot } com on 2005/07/27 02:15:23 Rate
try {
DatabaseMetaData dmd = cn.getMetaData ( ) ;
System.out.println ( dmd.getDriverName ( ) ) ; // Mark Matthew's MySQL Driver
System.out.println ( dmd.getDatabaseProductName ( ) ) ;
} catch ( SQLException e ) {
}
int getTransactionIsolation()
throws SQLException
- See Also:
setTransactionIsolation(int)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
Map<String,Class<?>> getTypeMap()
throws SQLException
- See Also:
setTypeMap(java.util.Map>)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
SQLWarning getWarnings()
throws SQLException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
boolean isClosed()
throws SQLException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
boolean isReadOnly()
throws SQLException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
String nativeSQL(String sql)
throws SQLException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
CallableStatement prepareCall(String sql)
throws SQLException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[320]Call SQL92 standard and Oracle stored procedure
By Anonymous on 2005/06/16 15:03:04 Rate
// SQL92 syntax
CallableStatement cs1 = conn.prepareCall ( " { call proc ( ?,? ) } " ) ; // stored proc
CallableStatement cs2 = conn.prepareCall ( " { ? = call func ( ?,? ) } " ) ; // stored func
// Oracle PL/SQL block syntax
CallableStatement cs3 = conn.prepareCall ( "begin proc ( ?,? ) ; end;" ) ; // stored proc
CallableStatement cs4 = conn.prepareCall ( "begin ? := func ( ?,? ) ; end;" ) ; // stored func
CallableStatement prepareCall(String sql,
int resultSetType,
int resultSetConcurrency)
throws SQLException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
CallableStatement prepareCall(String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
throws SQLException
- See Also:
ResultSet
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
PreparedStatement prepareStatement(String sql)
throws SQLException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[810]Delete record from database
By Anonymous on 2004/06/18 10:38:32 Rate
PreparedStatement pstmt = null;
Connection conn = null;
conn = getConnection ( ) ;
pstmt = conn.prepareStatement ( "delete from accounts where id = ?" ) ;
pstmt.setString ( 1, id ) ;
if ( pstmt.executeUpdate ( ) == 0 ) {
throw new RemoveException ( "Account " + pk + " failed to be removed from the database" ) ;
}
PreparedStatement prepareStatement(String sql,
int autoGeneratedKeys)
throws SQLException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
PreparedStatement prepareStatement(String sql,
int resultSetType,
int resultSetConcurrency)
throws SQLException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
PreparedStatement prepareStatement(String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
throws SQLException
- See Also:
ResultSet
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
PreparedStatement prepareStatement(String sql,
int[] columnIndexes)
throws SQLException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
PreparedStatement prepareStatement(String sql,
String[] columnNames)
throws SQLException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
void releaseSavepoint(Savepoint savepoint)
throws SQLException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
void rollback()
throws SQLException
- See Also:
setAutoCommit(boolean)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[1221]Typical JDBC transaction handling
By Anonymous on 2004/12/23 14:38:19 Rate
// an example of typical transaction handling code:
con.setAutoCommit ( false ) ;
...
bError = false;
try
{
for ( ... )
{
// validate data, set bError true if error
if ( bError )
{
break;
}
stmt.executeUpdate ( ... ) ;
}
if ( bError )
{
con.rollback ( ) ;
}
else
{
con.commit ( ) ;
}
} // end try
catch ( SQLException SQLe )
{
con.rollback ( ) ;
...
} // end catch
catch ( Exception e )
{
con.rollback ( ) ;
...
} // end catch
void rollback(Savepoint savepoint)
throws SQLException
- See Also:
rollback()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
void setAutoCommit(boolean autoCommit)
throws SQLException
- See Also:
getAutoCommit()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[298]Begin transaction
By Anonymous on 2003/10/26 13:39:25 Rate
conn.setAutoCommit ( false ) ; // Begin transaction
void setCatalog(String catalog)
throws SQLException
- See Also:
getCatalog()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
void setHoldability(int holdability)
throws SQLException
- See Also:
ResultSet
, getHoldability()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
void setReadOnly(boolean readOnly)
throws SQLException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
Savepoint setSavepoint()
throws SQLException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
Savepoint setSavepoint(String name)
throws SQLException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
void setTransactionIsolation(int level)
throws SQLException
- See Also:
getTransactionIsolation()
, DatabaseMetaData.supportsTransactionIsolationLevel(int)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
void setTypeMap(Map<String,Class<?>> map)
throws SQLException
- See Also:
getTypeMap()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
static final int TRANSACTION_NONE
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
static final int TRANSACTION_READ_COMMITTED
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
static final int TRANSACTION_READ_UNCOMMITTED
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
static final int TRANSACTION_REPEATABLE_READ
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
static final int TRANSACTION_SERIALIZABLE
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples