java database connectivity - jdbc part-2

25
Working with JDBC Working with JDBC By CHITRAKANT BANCHHOR

Upload: pranil-dukare

Post on 15-Jun-2015

208 views

Category:

Education


3 download

DESCRIPTION

JDBC Part-2, This was made by Prof. Chitrakant Banchhor Very Descriptive,Easy to Understand Thank You Sir......

TRANSCRIPT

Page 1: Java DataBase Connectivity - JDBC Part-2

Working with JDBCWorking with JDBCBy

CHITRAKANT BANCHHOR

Page 2: Java DataBase Connectivity - JDBC Part-2

ReferencesReferences

Page 3: Java DataBase Connectivity - JDBC Part-2

ConnectionConnection

StatementStatement

JDBC InterfacesJDBC Interfaces

StatementStatement

DatabaseMetaDataDatabaseMetaData

Page 4: Java DataBase Connectivity - JDBC Part-2

Connection InterfaceConnection Interface

Transaction processingTransaction processingCreate objects for

executing SQL statementsCreate objects for

executing SQL statements

methods for

Transaction processingTransaction processing

Create objects forexecuting stored

procedures

Create objects forexecuting stored

procedures

Create objects forexecuting SQL statements

Create objects forexecuting SQL statements

It can not directly be created in code; instead, the Connection interface is created by theDriver.connect() method.

Page 5: Java DataBase Connectivity - JDBC Part-2

createStatement()createStatement()

public Statement createStatementcreateStatement( )( ) throws SQLExceptionpublic Statement createStatementcreateStatement( )( ) throws SQLException

This method creates a Statement object associated with this Connection session.

public Statement createStatementcreateStatement( )( ) throws SQLException

public Statement createStatementcreateStatement ((intint resultSetTyperesultSetType,, intint resultSetConcurresultSetConcur

))throws SQLException

public Statement createStatementcreateStatement ((intint resultSetTyperesultSetType,, intint resultSetConcurresultSetConcur

))throws SQLException

Page 6: Java DataBase Connectivity - JDBC Part-2

prepareStatementprepareStatement

public PreparedStatement prepareStatementprepareStatement((String sqlsql

)) throws SQLException

public PreparedStatement prepareStatementprepareStatement((String sqlsql

)) throws SQLException

This method provides a PreparedStatement object to be associated with this Connection session.

public PreparedStatement prepareStatementprepareStatement((String sqlsql

)) throws SQLException

public PreparedStatement prepareStatementprepareStatement ((String sqlsql,,int resultSetTyperesultSetType,,int resultSetConcurresultSetConcur

)) throws SQLException

public PreparedStatement prepareStatementprepareStatement ((String sqlsql,,int resultSetTyperesultSetType,,int resultSetConcurresultSetConcur

)) throws SQLException

Page 7: Java DataBase Connectivity - JDBC Part-2

The StatementStatement Interface

• The Connection object connects to the database.

• To execute SQL statements and get results back from the database, wemust use the Statement object.

Page 8: Java DataBase Connectivity - JDBC Part-2

Statement object creationStatement object creation

It can not be created directlyIt can not be created directly

It is created by the method of theConnection object

It is created by the method of theConnection object

It is created by the method of theConnection object

It is created by the method of theConnection object

The createStatement() methodreturns a Statement object as a

return value

The createStatement() methodreturns a Statement object as a

return value

Page 9: Java DataBase Connectivity - JDBC Part-2

execution methods used with a Statement objectexecution methods used with a Statement object

1. It allows us to execute the Statement when we do notknow if it is a query or an update.

2. It may return multiple results.

3. Use getResultSet to retrieve the ResultSet.

boolean executeexecute(

String Sql)

Executes the SQL string and returns a singleResultSet object.Executes the SQL string and returns a singleResultSet object.

Executes a SQL string, which must be anINSERT,UPDATE, DELETE, or a statement thatdoesn’t return anything.

Executes a SQL string, which must be anINSERT,UPDATE, DELETE, or a statement thatdoesn’t return anything.

ResultSet executeQueryexecuteQuery(

String Sql)

int executeUpdateexecuteUpdate(

String Sql)

Page 10: Java DataBase Connectivity - JDBC Part-2

Example:Example: SelectSelect

Page 11: Java DataBase Connectivity - JDBC Part-2
Page 12: Java DataBase Connectivity - JDBC Part-2
Page 13: Java DataBase Connectivity - JDBC Part-2

Example: InsertExample: Insert

Page 14: Java DataBase Connectivity - JDBC Part-2

Example: DeleteExample: Delete

Page 15: Java DataBase Connectivity - JDBC Part-2

Example: Create TableExample: Create Table -- 11

Page 16: Java DataBase Connectivity - JDBC Part-2

Example: Create TableExample: Create Table -- 22

Page 17: Java DataBase Connectivity - JDBC Part-2
Page 18: Java DataBase Connectivity - JDBC Part-2

JDBC withJDBC with MySqlMySql

Page 19: Java DataBase Connectivity - JDBC Part-2

Required SoftwareRequired Software

Page 20: Java DataBase Connectivity - JDBC Part-2

MySqlMySql connector with Tomcatconnector with Tomcat

• Copy in Tomcat’s lib folder

Page 21: Java DataBase Connectivity - JDBC Part-2

Create Table :Create Table : MySqlMySql

Page 22: Java DataBase Connectivity - JDBC Part-2

Delete Table:Delete Table: MySqlMySql

Page 23: Java DataBase Connectivity - JDBC Part-2

Inserting values inInserting values in MySQLMySQL database tabledatabase table

Page 24: Java DataBase Connectivity - JDBC Part-2

Select:Select: MySqlMySql

Page 25: Java DataBase Connectivity - JDBC Part-2

Thank You!Thank You!Thank You!Thank You!