UNIT – 5
PART- II
JDBC DRIVER AND ITS TYPES
DATABASE URL FORMULATION
CREATE CONNECTION OBJECT
CLOSING JDBC CONNECTIONS
DATA TYPES
RESULT SETS
CONCURRENCY OF RESULTSET
VIEWING A RESULT SET
TRANSACTIONS
COMMIT & ROLLBACK
UNIT – 4
PART I
APPLET
APPLETS - GUI COMPONENTS
APPLET PARAMETERS
LIFE CYCLE OF AN APPLET
APPLICATION CONVERSION TO APPLETS
AWT AND AWT HIERARCHY
SWING COMPONENTS
UNIT - 2
ARRAY AND ITS TYPES
INHERITANCE AND ITS TYPES
THE SUPER KEYWORD
POLYMORPHISM
ABSTRACT CLASSES
INTERFACES
DECLARING INTERFACES
IMPLEMENTING INTERFACES
EXTENDED INTERFACES
EXTENDING MULTIPLE INTERFACES
PACKAGES
THE IMPORT KEYWORD
THE DIRECTORY STRUCTURE OF PACKAGES
ACCESS SPECIFIER
UNIT - 4
PART II
AWT EVENT HANDLING
AWT EVENT CLASSES
AWT EVENT LISTENERS
AWT ADAPTER CLASSES
AWT CONTAINERS
AWT LAYOUT MANAGER
AWT MENU CLASSES
MENU CONTROLS
AWT GRAPHICS CLASSES
GRAPHICS
WINDOW FUNDAMENTALS
WORKING WITH FRAME WINDOW
WORKING WITH GRAPHICS
UNIT – 4
PART I
APPLET
APPLETS - GUI COMPONENTS
APPLET PARAMETERS
LIFE CYCLE OF AN APPLET
APPLICATION CONVERSION TO APPLETS
AWT AND AWT HIERARCHY
SWING COMPONENTS
UNIT - 2
ARRAY AND ITS TYPES
INHERITANCE AND ITS TYPES
THE SUPER KEYWORD
POLYMORPHISM
ABSTRACT CLASSES
INTERFACES
DECLARING INTERFACES
IMPLEMENTING INTERFACES
EXTENDED INTERFACES
EXTENDING MULTIPLE INTERFACES
PACKAGES
THE IMPORT KEYWORD
THE DIRECTORY STRUCTURE OF PACKAGES
ACCESS SPECIFIER
UNIT - 4
PART II
AWT EVENT HANDLING
AWT EVENT CLASSES
AWT EVENT LISTENERS
AWT ADAPTER CLASSES
AWT CONTAINERS
AWT LAYOUT MANAGER
AWT MENU CLASSES
MENU CONTROLS
AWT GRAPHICS CLASSES
GRAPHICS
WINDOW FUNDAMENTALS
WORKING WITH FRAME WINDOW
WORKING WITH GRAPHICS
Moving complex enterprise ecommerce systems to the cloudElastic Path
Developing and operating an enterprise commerce ecosystem, with its complex integrations, can often be a significant challenge. Are you wondering if a migration to the cloud would be best for your business, or if it is even possible for your specific applications? In this webinar we will discuss some of the advantages and disadvantages of working in a Platform-as-a-Service (PaaS) environment, such as dealing with restricted classes, leveraging automatic scalability, and migrating the persistence layer. Learn from our experiences, as we reveal what worked best as we moved our own multi-server enterprise application from traditional collocated hardware into the Google App Engine cloud environment.
Laravel Framework is a popular PHP framework that is taking the web development community by storm. Laravel is the Most Starred PHP Framework on Github: more than 30 000 developers from all over the world (mostly from the USA) use it for custom software development.
Turbocharge SQL Performance in PL/SQL with Bulk ProcessingSteven Feuerstein
Is your Oracle Database application running slower than you'd like? One of the first things to check is row-by-row processing: non-query DML (insert, update, delete) within a loop. And the fix? Bulk processing, either with smarter SQL or with FORALL and BULK COLLECT in PL/SQL.
Moving complex enterprise ecommerce systems to the cloudElastic Path
Developing and operating an enterprise commerce ecosystem, with its complex integrations, can often be a significant challenge. Are you wondering if a migration to the cloud would be best for your business, or if it is even possible for your specific applications? In this webinar we will discuss some of the advantages and disadvantages of working in a Platform-as-a-Service (PaaS) environment, such as dealing with restricted classes, leveraging automatic scalability, and migrating the persistence layer. Learn from our experiences, as we reveal what worked best as we moved our own multi-server enterprise application from traditional collocated hardware into the Google App Engine cloud environment.
Laravel Framework is a popular PHP framework that is taking the web development community by storm. Laravel is the Most Starred PHP Framework on Github: more than 30 000 developers from all over the world (mostly from the USA) use it for custom software development.
Turbocharge SQL Performance in PL/SQL with Bulk ProcessingSteven Feuerstein
Is your Oracle Database application running slower than you'd like? One of the first things to check is row-by-row processing: non-query DML (insert, update, delete) within a loop. And the fix? Bulk processing, either with smarter SQL or with FORALL and BULK COLLECT in PL/SQL.
Mumbai Academics is Mumbai’s first dedicated Professional Training Center for Training with Spoke and hub model with Multiple verticles . The strong foundation of Mumbai Academics is laid by highly skilled and trained Professionals, carrying mission to provide industry level input to the freshers and highly skilled and trained Software Professionals/other professional to IT companies.
JDBC tutorial with full example, including CRUD sql statement with JDBC Statement and PreparedStatement, interact Stored Procedure with CallableStatement, JDBC transaction
MOBILE APPLICATIONS DEVELOPMENT -ANDROID BY SIVASANKARISivaSankari36
unit 1; ANDROID
Native and web applications - Mobile operating systems and applications - Mobile Databases. Android: History of Android - Android Features – OSS – OHA - Android Versions and compatibility - Android devices - Prerequisites to learn Android -– Setting up software – IDE - XML. Android Architecture: Android Stack - Linux Kernel - Android Runtime - Dalvik VM - Application Framework - Android emulator - Android applications.
UNIT II Android development:
Java - Android Studio – Eclipse – Virtualization – APIs and Android tools – Debugging with DDMS – Android File system – Working with emulator and smart devices - A Basic Android Application - Deployment. Android Activities: The Activity Lifecycle – Lifecycle methods – Creating Activity. Intents – Intent Filters – Activity stack.
UNIT III Android Services:
Simple services – Binding and Querying the service – Executing services.- Broadcast Receivers: Creating and managing receivers – Receiver intents – ordered broadcasts. Content Providers: Creating and using content providers – Content resolver. Working with databases: SQLite – coding for SQLite using Android – Sample database applications – Data analysis.
UNIT IV Android User Interface:
Android Layouts – Attributes – Layout styles - Linear – Relative – Table – Grid – Frame. Menus: Option menu – context menu - pop-up menu – Lists and Notifications: creation and display. Input Controls: Buttons-Text Fields-Checkboxes-alert dialogs-Spinners-rating bar-progress bar.
UNIT V Publishing and Internationalizing mobile applications :
Live mobile application development: Game, Clock, Calendar, Convertor, Phone book. App Deployment and Testing: Doodlz app – Tip calculator app – Weather viewer app.
Text Books
1. Barry Burd, “Android Application Development – All-in-one for Dummies”, 2nd Edition, Wiley India, 2016.
Reference
1. Paul Deitel, Harvey Deitel, Alexander Wald, “ Android 6 for Programmers – An App-driven Approach”, 3rd edition, Pearson education, 2016.
2. Jerome (J. F) DiMarzio, “Android – A Programmer‟s Guide”, McGraw Hill Education, 8th reprint, 2015.
3. http://www.developer.android.com
UNIT I -WIRELESS COMMUNICATION FUNDAMENTALS
UNIT II -TELECOMMUNICATION NETWORKS & WIRLESS LAN
UNIT III -MOBILE NETWORK LAYER & TRANSPORT LAYER
UNIT IV- APPLICATION LAYER
UNIT V- DATABASE ISSUES
Functional MRI using Apache Spark in Big Data ApplicationSivaSankari36
Technologies for ascendable investigation of terribly massive datasets have emerge within the domain of web computing, however are still seldom utilized in neuroimaging despite the existence of knowledge and analysis queries in want of economical computation tools particularly in fMRI
Ethnobotany and Ethnopharmacology:
Ethnobotany in herbal drug evaluation,
Impact of Ethnobotany in traditional medicine,
New development in herbals,
Bio-prospecting tools for drug discovery,
Role of Ethnopharmacology in drug evaluation,
Reverse Pharmacology.
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
Synthetic fiber production is a fascinating and complex field that blends chemistry, engineering, and environmental science. By understanding these aspects, students can gain a comprehensive view of synthetic fiber production, its impact on society and the environment, and the potential for future innovations. Synthetic fibers play a crucial role in modern society, impacting various aspects of daily life, industry, and the environment. ynthetic fibers are integral to modern life, offering a range of benefits from cost-effectiveness and versatility to innovative applications and performance characteristics. While they pose environmental challenges, ongoing research and development aim to create more sustainable and eco-friendly alternatives. Understanding the importance of synthetic fibers helps in appreciating their role in the economy, industry, and daily life, while also emphasizing the need for sustainable practices and innovation.
Instructions for Submissions thorugh G- Classroom.pptxJheel Barad
This presentation provides a briefing on how to upload submissions and documents in Google Classroom. It was prepared as part of an orientation for new Sainik School in-service teacher trainees. As a training officer, my goal is to ensure that you are comfortable and proficient with this essential tool for managing assignments and fostering student engagement.
How to Make a Field invisible in Odoo 17Celine George
It is possible to hide or invisible some fields in odoo. Commonly using “invisible” attribute in the field definition to invisible the fields. This slide will show how to make a field invisible in odoo 17.
Operation “Blue Star” is the only event in the history of Independent India where the state went into war with its own people. Even after about 40 years it is not clear if it was culmination of states anger over people of the region, a political game of power or start of dictatorial chapter in the democratic setup.
The people of Punjab felt alienated from main stream due to denial of their just demands during a long democratic struggle since independence. As it happen all over the word, it led to militant struggle with great loss of lives of military, police and civilian personnel. Killing of Indira Gandhi and massacre of innocent Sikhs in Delhi and other India cities was also associated with this movement.
Model Attribute Check Company Auto PropertyCeline George
In Odoo, the multi-company feature allows you to manage multiple companies within a single Odoo database instance. Each company can have its own configurations while still sharing common resources such as products, customers, and suppliers.
The Art Pastor's Guide to Sabbath | Steve ThomasonSteve Thomason
What is the purpose of the Sabbath Law in the Torah. It is interesting to compare how the context of the law shifts from Exodus to Deuteronomy. Who gets to rest, and why?
1.4 modern child centered education - mahatma gandhi-2.pptx
PROGRAMMING IN JAVA- unit 5-part II
1. PROGRAMMING IN JAVA
A. SIVASANKARI
ASSISTANT PROFESSOR
DEPARTMENT OF COMPUTER APPLICATION
SHANMUGA INDUSTRIES ARTS AND SCIENCE
COLLEGE,
TIRUVANNAMALAI. 606601.
Email: sivasankaridkm@gmail.com
2. PROGRAMMING IN JAVA
UNIT – 5
PART- II
JDBC DRIVER AND ITS TYPES
DATABASE URL FORMULATION
CREATE CONNECTION OBJECT
CLOSING JDBC CONNECTIONS
DATA TYPES
RESULT SETS
CONCURRENCY OF RESULTSET
VIEWING A RESULT SET
TRANSACTIONS
COMMIT & ROLLBACK
A. SIVASANKARI - SIASC-TVM UNIT-5
3. PROGRAMMING IN JAVA
JDBC - DRIVER AND ITS TYPES
DEFINITION OF JDBC DRIVER
• JDBC drivers implement the defined interfaces in the JDBC API, for interacting with your
database server.
• For example, using JDBC drivers enable you to open database connections and to
interact with it by sending SQL or database commands then receiving results with Java.
• The Java.sql package that ships with JDK, contains various classes with their behaviours
defined and their actual implementaions are done in third-party drivers. Third party vendors
implements the java.sql.Driver interface in their database driver.
JDBC DRIVERS TYPES
• JDBC driver implementations vary because of the wide variety of operating systems and
hardware platforms in which Java operates. Such has divided the implementation types into
four categories, Types 1, 2, 3, and 4, which is explained below −
Type 1: JDBC-ODBC Bridge Driver
• In a Type 1 driver, a JDBC bridge is used to access ODBC drivers installed on each client
machine. Using ODBC, requires configuring on your system a Data Source Name (DSN) that
represents the target database.
• When Java first came out, this was a useful driver because most databases only supported
ODBC access but now this type of driver is recommended only for experimental use or when
no other alternative is available.
A. SIVASANKARI - SIASC-TVM
4. PROGRAMMING IN JAVA
• The JDBC-ODBC Bridge that comes with JDK 1.2 is a good example of
this kind of driver.
A. SIVASANKARI - SIASC-TVM
5. PROGRAMMING IN JAVA
Type 2: JDBC-Native API
• In a Type 2 driver, JDBC API calls are converted into native C/C++ API calls, which
are unique to the database. These drivers are typically provided by the database
vendors and used in the same manner as the JDBC-ODBC Bridge. The vendor-specific
driver must be installed on each client machine.
• If we change the Database, we have to change the native API, as it is specific to a
database and they are mostly obsolete now, but you may realize some speed increase
with a Type 2 driver, because it eliminates ODBC's overhead.
• The Oracle Call Interface (OCI) driver is an example of a Type 2 driver.
A. SIVASANKARI - SIASC-TVM
6. PROGRAMMING IN JAVA
• Type 3: JDBC-Net pure Java
• In a Type 3 driver, a three-tier approach is used to access databases. The JDBC clients
use standard network sockets to communicate with a middleware application server. The
socket information is then translated by the middleware application server into the call
format required by the DBMS, and forwarded to the database server.
• This kind of driver is extremely flexible, since it requires no code installed on the client
and a single driver can actually provide access to multiple databases.
A. SIVASANKARI - SIASC-TVM
7. PROGRAMMING IN JAVA
Type 4: 100% Pure Java
• In a Type 4 driver, a pure Java-based driver communicates directly with the vendor's database
through socket connection. This is the highest performance driver available for the database
and is usually provided by the vendor itself.
• This kind of driver is extremely flexible, you don't need to install special software on the
client or server. Further, these drivers can be downloaded dynamically.
• MySQL's Connector/J driver is a Type 4 driver. Because of the proprietary nature of their
network protocols, database vendors usually supply type 4 drivers.
A. SIVASANKARI - SIASC-TVM
8. PROGRAMMING IN JAVA
WHICH DRIVER SHOULD BE USED?
• If we are accessing one type of database, such as Oracle, Sybase, or IBM, the preferred driver
type is 4.
• If our Java application is accessing multiple types of databases at the same time, type 3 is the
preferred driver.
• Type 2 drivers are useful in situations, where a type 3 or type 4 driver is not available yet for
your database.
• The type 1 driver is not considered a deployment-level driver, and is typically used for
development and testing purposes only.
JDBC - DATABASE CONNECTIONS
• After you've installed the appropriate driver, it is time to establish a database connection using
JDBC.
• The programming involved to establish a JDBC connection is fairly simple. Here are these
simple four steps −
• Import JDBC Packages: Add import statements to your Java program to import required
classes in your Java code.
• Register JDBC Driver: This step causes the JVM to load the desired driver implementation
into memory so it can fulfill your JDBC requests.
• Database URL Formulation: This is to create a properly formatted address that points to the
database to which you wish to connect.
• Create Connection Object: Finally, code a call to
the DriverManager object's getConnection( ) method to establish actual database connection.
A. SIVASANKARI - SIASC-TVM
9. PROGRAMMING IN JAVA
DATABASE URL FORMULATION
• After you've loaded the driver, you can establish a connection using
the DriverManager.getConnection() method. For easy reference, let me list the three
overloaded DriverManager.getConnection() methods −
• getConnection(String url)
• getConnection(String url, Properties prop)
• getConnection(String url, String user, String password)
• Here each form requires a database URL. A database URL is an address that points to your
database.
• Formulating a database URL is where most of the problems associated with establishing a
connection occurs.
• Following table lists down the popular JDBC driver names and database URL.
RDBMS JDBC driver name URL format
MySQL com.mysql.jdbc.Driver jdbc:mysql://hostname/ databaseName
ORACLE oracle.jdbc.driver.OracleDriver jdbc:oracle:thin:@hostname:port Number:databaseName
DB2 COM.ibm.db2.jdbc.net.DB2Driver jdbc:db2:hostname:port Number/databaseName
Sybase com.sybase.jdbc.SybDriver jdbc:sybase:Tds:hostname: port Number/databaseName
A. SIVASANKARI - SIASC-TVM
10. PROGRAMMING IN JAVA
CREATE CONNECTION OBJECT
• We have listed down three forms of DriverManager.getConnection() method to create a
connection object.
• Using a Database URL with a username and password
• The most commonly used form of getConnection() requires you to pass a database URL,
a username, and a password:
• Assuming you are using Oracle's thin driver, you'll specify a host:port: databaseName value
for the database portion of the URL.
• If you have a host at TCP/IP address 192.0.0.1 with a host name of am rood, and your Oracle
listener is configured to listen on port 1521, and your database name is EMP, then complete
database URL would be −
• jdbc:oracle:thin:@amrood:1521:EMP
• Now you have to call getConnection() method with appropriate username and password to get
a Connection object as follows −
• String URL = "jdbc:oracle:thin:@amrood:1521:EMP";String USER = "username";String
PASS = "password"Connection conn = DriverManager.getConnection(URL, USER, PASS);
A. SIVASANKARI - SIASC-TVM
11. PROGRAMMING IN JAVA
USING ONLY A DATABASE URL
• A second form of the DriverManager.getConnection( ) method requires only a database URL
• DriverManager.getConnection(String url);
• However, in this case, the database URL includes the username and password and has the
following general form −
• jdbc:oracle:driver:username/password@database
• So, the above connection can be created as follows −
• String URL = "jdbc:oracle:thin:username/password@amrood:1521:EMP";Connection conn =
DriverManager.getConnection(URL);
USING A DATABASE URLAND A PROPERTIES OBJECT
• A third form of the DriverManager.getConnection( ) method requires a database URL and a
Properties object −
• DriverManager.getConnection(String url, Properties info);
• A Properties object holds a set of keyword-value pairs. It is used to pass driver properties to
the driver during a call to the getConnection() method.
• To make the same connection made by the previous examples, use the following code −
• import java.util.*; String URL = "jdbc:oracle:thin:@amrood:1521:EMP";
• Properties info = new Properties( );
• info.put( "user", "username" );
• info.put( "password", "password" );
• Connection conn = DriverManager.getConnection(URL, info);
A. SIVASANKARI - SIASC-TVM
12. PROGRAMMING IN JAVA
CLOSING JDBC CONNECTIONS
• At the end of your JDBC program, it is required explicitly to close all the connections to
the database to end each database session. However, if you forget, Java's garbage
collector will close the connection when it cleans up stale objects.
• Relying on the garbage collection, especially in database programming, is a very poor
programming practice. You should make a habit of always closing the connection
with the close() method associated with connection object.
• To ensure that a connection is closed, you could provide a 'finally' block in your code.
A finally block always executes, regardless of an exception occurs or not.
• To close the above opened connection, you should call close() method as follows −
• conn.close();
A. SIVASANKARI - SIASC-TVM
13. PROGRAMMING IN JAVA
JDBC - Statements, PreparedStatement and callableStatement
• Once a connection is obtained we can interact with the database. The JDBC Statement,
CallableStatement, and PreparedStatement interfaces define the methods and properties that
enable you to send SQL or PL/SQL commands and receive data from your database.
• They also define methods that help bridge data type differences between Java and SQL data
types used in a database.
• The following table provides a summary of each interface's purpose to decide on the interface
to use.Interfaces Recommended Use
Statement Use this for general-purpose access to your database. Useful when you
are using static SQL statements at runtime. The Statement interface
cannot accept parameters.
PreparedStatement Use this when you plan to use the SQL statements many times. The
PreparedStatement interface accepts input parameters at runtime.
CallableStatement Use this when you want to access the database stored procedures. The
CallableStatement interface can also accept runtime input parameters.
A. SIVASANKARI - SIASC-TVM
14. PROGRAMMING IN JAVA
JDBC - DATA TYPES
• The JDBC driver converts the Java data type to the appropriate JDBC type, before sending it
to the database. It uses a default mapping for most data types. For example, a Java int is
converted to an SQL INTEGER. Default mappings were created to provide consistency
between drivers.
• The following table summarizes the default JDBC data type that the Java data type is
converted to, when you call the setXXX() method of the PreparedStatement or
CallableStatement object or the ResultSet.updateXXX() method.
A. SIVASANKARI - SIASC-TVM
15. PROGRAMMING IN JAVA
SQL JDBC/Java setXXX updateXXX
VARCHAR java.lang.String setString updateString
CHAR java.lang.String setString updateString
LONGVARCHAR java.lang.String setString updateString
BIT boolean setBoolean updateBoolean
NUMERIC java.math.BigDecimal setBigDecimal updateBigDecimal
TINYINT byte setByte updateByte
SMALLINT short setShort updateShort
INTEGER int setInt updateInt
BIGINT long setLong updateLong
REAL float setFloat updateFloat
FLOAT float setFloat updateFloat
DOUBLE double setDouble updateDouble
VARBINARY byte[ ] setBytes updateBytes
BINARY byte[ ] setBytes updateBytes
DATE java.sql.Date setDate updateDate
TIME java.sql.Time setTime updateTime
TIMESTAMP java.sql.Timestamp setTimestamp updateTimestamp
A. SIVASANKARI - SIASC-TVM
16. PROGRAMMING IN JAVA
JDBC - RESULT SETS
• The SQL statements that read data from a database query, return the data in a result
set. The SELECT statement is the standard way to select rows from a database
and view them in a result set. The java.sql.ResultSet interface represents the result
set of a database query.
• A ResultSet object maintains a cursor that points to the current row in the result set.
The term "result set" refers to the row and column data contained in a ResultSet
object.
A. SIVASANKARI - SIASC-TVM
17. PROGRAMMING IN JAVA
The methods of the ResultSet interface can be broken down into three
categories
• Navigational methods: Used to move the cursor around.
• Get methods: Used to view the data in the columns of the current row
being pointed by the cursor.
• Update methods: Used to update the data in the columns of the current
row. The updates can then be updated in the underlying database as well.
• The cursor is movable based on the properties of the ResultSet. These
properties are designated when the corresponding Statement that generates
the ResultSet is created.
JDBC provides the following connection methods to create statements with
desired ResultSet −
• createStatement(int RSType, int RSConcurrency);
• prepareStatement(String SQL, int RSType, int RSConcurrency);
• prepareCall(String sql, int RSType, int RSConcurrency);
• The first argument indicates the type of a ResultSet object and the second
argument is one of two ResultSet constants for specifying whether a result
set is read-only or updatable.
.
A. SIVASANKARI - SIASC-TVM
18. PROGRAMMING IN JAVA
TYPES OF RESULTSET DESCRIPTION
ResultSet.TYPE_FORWARD_ONLY The cursor can only move forward in the result set.
ResultSet.TYPE_SCROLL_INSENSITIVE The cursor can scroll forward and backward, and
the result set is not sensitive to changes made by
others to the database that occur after the result set
was created.
ResultSet.TYPE_SCROLL_SENSITIVE. The cursor can scroll forward and backward, and
the result set is sensitive to changes made by others
to the database that occur after the result set was
created.
A. SIVASANKARI - SIASC-TVM
TYPE OF RESULTSET
The possible RSType are given below. If you do not specify any ResultSet type, you
will automatically get one that is TYPE_FORWARD_ONLY.
19. PROGRAMMING IN JAVA
CONCURRENCY OF RESULTSET
• The possible RSConcurrency are given below. If you do not specify any Concurrency type,
you will automatically get one that is CONCUR_READ_ONLY.
• All our examples written so far can be written as follows, which initializes a Statement object
to create a forward-only, read only ResultSet object −
• try {
• Statement stmt = conn.createStatement( ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY);}
• catch(Exception ex)
• { ....}
• finally
• { ....}
CONCURRENCY DESCRIPTION
ResultSet.CONCUR_READ_ONLY Creates a read-only result set. This is the default
ResultSet.CONCUR_UPDATABLE Creates an updateable result set.
A. SIVASANKARI - SIASC-TVM
20. PROGRAMMING IN JAVA
VIEWING A RESULT SET
• The ResultSet interface contains dozens of methods for getting the data of the current row.
• There is a get method for each of the possible data types, and each get method has two
versions −
• One that takes in a column name.
• One that takes in a column index.
S.N. METHODS & DESCRIPTION
1 public int getInt(String columnName) throws SQLException
Returns the int in the current row in the column named columnName.
2 public int getInt(int columnIndex) throws SQLException
Returns the int in the current row in the specified column index. The column index
starts at 1, meaning the first column of a row is 1, the second column of a row is 2,
and so on.
A. SIVASANKARI - SIASC-TVM
21. PROGRAMMING IN JAVA
JDBC - TRANSACTIONS
• If our JDBC Connection is in auto-commit mode, which it is by default, then every SQL
statement is committed to the database upon its completion.
• That may be fine for simple applications, but there are three reasons why you may want to
turn off the auto-commit and manage your own transactions −
• To increase performance.
• To maintain the integrity of business processes.
• To use distributed transactions.
• Transactions enable you to control if, and when, changes are applied to the database. It treats
a single SQL statement or a group of SQL statements as one logical unit, and if any statement
fails, the whole transaction fails.
• To enable manual- transaction support instead of the auto-commit mode that the JDBC driver
uses by default, use the Connection object's setAutoCommit() method. If you pass a boolean
false to setAutoCommit( ), you turn off auto-commit. You can pass a boolean true to turn it
back on again.
• For example, if you have a Connection object named conn, code the following to turn off
auto-commit −
• conn.setAutoCommit(false);
A. SIVASANKARI - SIASC-TVM
22. PROGRAMMING IN JAVACOMMIT & ROLLBACK
Once you are done with your changes and you want to commit the changes then
call commit() method on connection object as follows
• conn.commit( );
Otherwise, to roll back updates to the database made using the Connection named conn, use the
following code −
• conn.rollback( );
The following example illustrates the use of a commit and rollback object −
• try{ //Assume a valid connection object
• conn conn.setAutoCommit(false);
• Statement stmt = conn.createStatement();
• String SQL = "INSERT INTO Employees " +
• "VALUES (106, 20, 'Rajesh', ‘Babu')";
• stmt.executeUpdate(SQL);
• //Submit a malformed SQL statement that breaks
• String SQL = "INSERTED IN Employees " +
• "VALUES (107, 22, 'Sobia', 'Suresh')";
• stmt.executeUpdate(SQL); // If there is no error.
• conn.commit();}
• catch(SQLException se){ // If there is any error.
• conn.rollback();
• }
A. SIVASANKARI - SIASC-TVM