Se ha denunciado esta presentación.
Se está descargando tu SlideShare. ×
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Próximo SlideShare
Jdbc connectivity in java
Jdbc connectivity in java
Cargando en…3
×

Eche un vistazo a continuación

1 de 15 Anuncio

Más Contenido Relacionado

Anuncio

Más reciente (20)

Jdbc

  1. 1. A presentation about Java Database Connectivity Name: Md. Easin Arafat Chowdhury Department: CSE Student Id: 162015040 Green University of Bangladesh Name: Md. Easin Arafat Chowdhury Department: CSE Student Id: 162015040 Green University of Bangladesh
  2. 2. Overview of JDBC Java Database Connectivity (JDBC) is an application programming interface (API) for the programming language Java, which defines how a client may access a database. It is part of the Java Standard Edition platform, from Oracle Corporation. It provides methods to query and update data in a database, and is oriented towards relational databases. 2
  3. 3. Architecture of JDBC 3
  4. 4. Types of JDBC drivers • Type-1: jdbc-odbc bridge drivers. • Type-2: native API partly java driver. • Type-3: net protocols all java drivers. • Type-4: native protocols all java drivers. 4
  5. 5. Steps to Connect ? • Define the connection URL. • Established the connection. • Create the statement object. • Execute a query. • Process the results. • Close the connection. 5
  6. 6. Steps to Connect ? • Define the connection URL : Class.for Name(); • For jdbc-odbc bridge driver:- Class.for Name(“ sun.jdbc.odbc.JdbcOdbcDriver”); • For Oracle driver:- Class.for Name(“oracle.jdbc.driver.OracleDriver”); • For My SQL driver:- Class.for Name(“com.mysql.jdbcDriver”); 6
  7. 7. Steps to Connect ? • Established the connection: Connection con = DriverManager.getConnection(“ url”, “user_name”, “pass”) • Create the statement object: Statement stmt = con.createStatement(); 7
  8. 8. Steps to Connect ? • Execute the query:- For the SELECT query- String sql = “ SELECT * FROM EMP”; Stmt.executeQuery(sql); For the INSERT and UPDATE query- String sql = “INSERT INTO EMP VALUES(47, “ TEDDY”)”; Stmt.executeUpdate(sql); 8
  9. 9. Steps to Connect ? • Close the connection and release all the resources that the connection is holding. Stmt.close(); Con.close(); 9
  10. 10. Types of Statement available • There are three types of statement are available in statement class:- Statement Prepared Statement Callable Statement 10
  11. 11. JDBC Data Source • The JDBS data source interface is an alternative to DriverManager class and conventional JDBC url. All the database information is present in the naming service and retrieved using the JNDI API. The Data Source object contrains the connection information which will make the actual connection and execute the JDBC commands. 11
  12. 12. JDBC Data Source • Each Data Source is assigned a logical name by conventional beginning with jdbc /. • Advantage :- Make the code portable and reuse. The application does not have to remember the hardcore driver information. Connection pooling and distributed transaction advantages is facilitate. 12
  13. 13. JDBC Data Source • Syntax:- Context ctx = new initial Context(); Data Source:- ds = (Data Source)ctx.lookup(“ jdbc/teddyDB”); Connection:- Con = ds.getConnection(“ user_name”, “pass”); 13
  14. 14. 14
  15. 15. 15

×