Download - Java DataBase Connectivity - JDBC Part-2
Working with JDBCWorking with JDBCBy
CHITRAKANT BANCHHOR
ReferencesReferences
ConnectionConnection
StatementStatement
JDBC InterfacesJDBC Interfaces
StatementStatement
DatabaseMetaDataDatabaseMetaData
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.
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
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
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.
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
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)
Example:Example: SelectSelect
Example: InsertExample: Insert
Example: DeleteExample: Delete
Example: Create TableExample: Create Table -- 11
Example: Create TableExample: Create Table -- 22
JDBC withJDBC with MySqlMySql
Required SoftwareRequired Software
MySqlMySql connector with Tomcatconnector with Tomcat
• Copy in Tomcat’s lib folder
Create Table :Create Table : MySqlMySql
Delete Table:Delete Table: MySqlMySql
Inserting values inInserting values in MySQLMySQL database tabledatabase table
Select:Select: MySqlMySql
Thank You!Thank You!Thank You!Thank You!