Mr. Harish Sharma Asst. Professor Dept. of CA & IT SGRRITS Dehradun

Slides:



Advertisements
Similar presentations
Connecting to Databases. connecting to DB DB server typically a standalone application Server runs on localhost for smaller sites –i.e. Same machine as.
Advertisements

Connecting to Databases. relational databases tables and relations accessed using SQL database -specific functionality –transaction processing commit.
Copyright  Oracle Corporation, All rights reserved. 2 Java and Databases: An Overview.
Java Database Connectivity (JDBC). 2/24 JDBC (Java DataBase Connectivity) - provides access to relational database systems JDBC is a vendor independent.
Distributed Application Development B. Ramamurthy.
1 Lecture 29 More on JDBC Overview  Objectives of this lecture  JDBC and its Drivers  Connecting to Databases (Java’s Connection class)  Querying a.
JDBC / ODBC JDBC is the java API that facilitate interaction of a java application with the DBMS. FIRST APPROACH:
Dale Roberts 8/24/ Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
Getting connected.  Java application calls the JDBC library.  JDBC loads a driver which talks to the database.  We can change database engines without.
JDBC Vs. Java Blend Presentation by Gopal Manchikanti Shivakumar Balasubramanyam.
Java Database Connectivity (JDBC) Francisco Pajaro Saul Acosta Nahum Quezada Manuel Rubio.
Java Database Connectivity (JDBC). Introduction Database –Collection of data DBMS –Database management system –Storing and organizing data SQL –Relational.
1 Java Database Connection (JDBC) There are many industrial-strength DBMS's commercially available in the market. Oracle, DB2, and Sybase are just a few.
Oracle8 JDBC Drivers Section 2. Common Features of Oracle JDBC Drivers The server-side and client-side Oracle JDBC drivers provide the same basic functionality.
Helena Pomezná, ciz034 St. skupina: L392 FEI, VŠB-TUO Ak. rok. 2002/2003 Download:
Basics of Web Databases With the advent of Web database technology, Web pages are no longer static, but dynamic with connection to a back-end database.
Java Database Connectivity Vijayan Sugumaran Department of DIS Oakland University.
© Wang Bin 2004 JDBC ----Java Database Connectivity.
CSE470 Software Engineering Fall Database Access through Java.
Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.
What is JDBC? Java Database Connectivity (JDBC) is an API for the Java programming language that defines how a client may access a database. provides.
Database Programming in Java Corresponds with Chapter 32, 33.
Fundamentals of Database Chapter 7 Database Technologies.
Designing and Developing WS B. Ramamurthy. Plans We will examine the resources available for development of JAX-WS based web services. We need an IDE,
CS 405G: Introduction to Database Systems Database programming.
Connecting to Oracle using Java November 4, 2009 David Goldschmidt, Ph.D. David Goldschmidt, Ph.D.
JDBC Enterprise Systems Programming. JDBC  Java Database Connectivity  Database Access Interface provides access to a relational database (by allowing.
Accessing Database using JDBC. JDBC Objectives Gain basic knowledge of Java JDBC Become familiar with the basics of interacting with a database using.
WEB/DB1 DATABASE PROGRAMMING 3JDBC by the ASU Scholars.
Java Database Connectivity (JDBC). Topics 1. The Vendor Variation Problem 2. SQL and Versions of JDBC 3. Creating an ODBC Data Source 4. Simple Database.
JDBC. Java.sql.package The java.sql package contains various interfaces and classes used by the JDBC API. This collection of interfaces and classes enable.
JDBC CS 124. JDBC Java Database Connectivity Database Access Interface provides access to a relational database (by allowing SQL statements to be sent.
Session 30 Basics of JDBC. Java Simplified / Session 30 / 2 of 33 Review A Swing menu consists of a menubar, menuitems and menus. Trees are used to depict.
12/6/2015B.Ramamurthy1 Java Database Connectivity B.Ramamurthy.
JDBC
Java and Databases. JDBC Architecture Java Application JDBC API Data Base Drivers AccessSQL Server DB2InformixMySQLSybase.
UNIT III - JDBC JDBC Overview – JDBC implementation – Connection class – Statements - Catching Database Results, handling database Queries. Networking–
Database Access Using JDBC BCIS 3680 Enterprise Programming.
CSI 3125, Preliminaries, page 1 JDBC. CSI 3125, Preliminaries, page 2 JDBC JDBC stands for Java Database Connectivity, which is a standard Java API (application.
Access Databases from Java Programs via JDBC Tessema M. Mengistu Department of Computer Science Southern Illinois University Carbondale
Basics of JDBC Session 14.
JDBC Chapter 1 JDBC Introduction
JDBC - Java Database Connectivity. JDBC provides Java applications with access to most database systems via SQL The architecture and API closely resemble.
Advanced Java Session 5 New York University School of Continuing and Professional Studies.
Ch. NoNameMarks 01AWT24 02Networking18 03JDBC20 04Swing18 05Servlet20 Advance Java Programming.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Java Database Connectivity.
Intro to JDBC Joseph Sant Applied Computing and Engineering Sciences Sheridan ITAL.
6-1 JAVA DATABASE CONNECTOR Colorado Technical University IT420 Tim Peterson.
Java and database. 3 Relational Databases A relational Database consists of a set of simple rectangular tables or relations The column headings are.
R EMAINING TOPICS IN JDBC Sagun Dhakhwa. O VERVIEW Introduction to JDBC API Types of JDBC Drivers Introduction to ODBC.
Instructor: Jinze Liu Fall /8/2016Jinze University of Kentucky 2 Database Project Database Architecture Database programming.
DEPTT. OF COMP. SC & APPLICATIONS
Note: To complete the examples in this section you need access to a database!! Most of the examples work for any database with JDBC drivers. However, connecting.
Interacting with Database
ODBC, OCCI and JDBC overview
JDBC Database Management Database connectivity
Web Technologies IT230 Dr Mohamed Habib.
JDBC 21-Aug-18.
Chapter 16 JAVA DATABASE CONNECTIVITY
Objectives In this lesson, you will learn about:
Interacting with Database
JDBC – ODBC DRIVERS.
Java Database Connectivity
Using a Database with JDBC
Introduction of Week 11 Return assignment 9-1 Collect assignment 10-1
JAVA DATABaSE CONNECTIVITY
ODBC and JDBC.
Introduction of Week 5 Assignment Discussion
Presentation transcript:

Mr. Harish Sharma Asst. Professor Dept. of CA & IT SGRRITS Dehradun JDBC Mr. Harish Sharma Asst. Professor Dept. of CA & IT SGRRITS Dehradun

Mr. Harish Sharma, Asst. prof., Dept. of CA & IT, SGRRITS, Dehradun JDBC The database is the heart of any business system. The business objects that make up an enterprise need some way to make sure they are saved across time. The database engine provides that storage mechanism. SQL was a key first step in simplifying database access. Java’s API builds on that foundation and provides you with shared language through which your application can talk to database engine. Java Data Base Connectivity (JDBC) accomplish its goal through a set of Java interfaces, each implemented differently by individual vendors. The set of classes that implement the JDBC interfaces for a particular database engine is called a JDBC driver. The JDBC API support both two tier and three – tier processing architecture for the database access. Mr. Harish Sharma, Asst. prof., Dept. of CA & IT, SGRRITS, Dehradun

Mr. Harish Sharma, Asst. prof., Dept. of CA & IT, SGRRITS, Dehradun JDBC Mr. Harish Sharma, Asst. prof., Dept. of CA & IT, SGRRITS, Dehradun

Mr. Harish Sharma, Asst. prof., Dept. of CA & IT, SGRRITS, Dehradun Database Driver JDBC Drivers are of four types as follows:   Type 1 These drivers use a bridging technology to access a database. The JDBC-ODBC bridge that comes with JDK. Advantages: It acts as a good approach for learning JDBC. It may be useful for companies that already have ODBC drivers installed on each client machine — typically Mr. Harish Sharma, Asst. prof., Dept. of CA & IT, SGRRITS, Dehradun

Mr. Harish Sharma, Asst. prof., Dept. of CA & IT, SGRRITS, Dehradun the case for Windows-based machines running productivity applications. It may be the only way to gain access to some low-end desktop databases.   Disadvantage: It is not suitable for large-scale applications. They are the slowest of all. The performance of system may suffer because there is some overhead associated with the translation work to go from JDBC to ODBC. It doesn’t support all the features of Java. User is limited by the functionality of the underlying ODBC driver, as it is product of different vendor Mr. Harish Sharma, Asst. prof., Dept. of CA & IT, SGRRITS, Dehradun

Mr. Harish Sharma, Asst. prof., Dept. of CA & IT, SGRRITS, Dehradun Type 2 Type 2 driver are native API drivers. This means that the driver contains Java code that calls native C or C++ methods provided by the individual database vendors that performs database access.   Advantage: It has a better performance than that of Type 1, in part because the Type 2 driver contains compiled code that's optimized for the back-end database server’s operating system. Disadvantage: For this, User needs to make sure the JDBC driver of the database vendor is loaded onto each client machine. Must have compiled code for every operating system that the application will run on. Best use is for controlled environments, such as an intranet. Mr. Harish Sharma, Asst. prof., Dept. of CA & IT, SGRRITS, Dehradun

Mr. Harish Sharma, Asst. prof., Dept. of CA & IT, SGRRITS, Dehradun Type 3 The type 3 drivers provide a client with a generic network API that is then translated into database – specific access at the server level. In other words, the JDBC driver on the client uses socket to call middleware application on the server that translates the client requests into an API specific to the desired driver.   Advantage: It has better performance than Types 1 and 2. It can be used when a company has multiple databases and wants to use a single JDBC driver to connect to all of them. Since, it is server-based, so there is no requirement for JDBC driver code on client machine. For performance reasons, the back-end server component is optimized for the operating system that the database is running on. Disadvantage: It needs some database-specific code on the middleware server. If the middleware is to run on different platforms, then Type 4 driver might be more effective. Mr. Harish Sharma, Asst. prof., Dept. of CA & IT, SGRRITS, Dehradun

Mr. Harish Sharma, Asst. prof., Dept. of CA & IT, SGRRITS, Dehradun Type 4 Type 4 uses network protocols built into the database engine. Fully Java technology enabled .Type 4 drivers talk directly to the database using Java sockets. This is the most direct pure Java solution. Advantage: It again has better performance than Types 1 and 2 and there is no need to install special software on client or server. It can be downloaded dynamically.   Disadvantage: It is not optimized for server operating system, so the driver can’t take advantage of operating system features. For this, user needs a different driver for each different database. Mr. Harish Sharma, Asst. prof., Dept. of CA & IT, SGRRITS, Dehradun

Mr. Harish Sharma, Asst. prof., Dept. of CA & IT, SGRRITS, Dehradun The JDBC API Mr. Harish Sharma, Asst. prof., Dept. of CA & IT, SGRRITS, Dehradun

Mr. Harish Sharma, Asst. prof., Dept. of CA & IT, SGRRITS, Dehradun The important interfaces are: java.sql.DriverManager which handles loading of driver and helps in creating new database connection java.sql.Connection establish connection to a particular database. java.sql.Statement used to execute SQL queries java.sql.ResultSet help to control database record access. Mr. Harish Sharma, Asst. prof., Dept. of CA & IT, SGRRITS, Dehradun

Establishing connection to the Databse Loading MS-Access Driver through JDBC-ODBC   try { Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”); } catch (ClassNotFoundException e) - - - Mr. Harish Sharma, Asst. prof., Dept. of CA & IT, SGRRITS, Dehradun

Define the connection URL JDBC url are defined as: jdbc: <subprotocol> :<subname> Connection k = DriverManager.getConnection(url, userid, passwd);   The DriverManager passes that Connection object back to the application. The url specifies the data source, userid is users login name to the database. Connection k = DriverManager.getConnection(“jdbc:odbc:test”, “harish”,”sgrrits”); Mr. Harish Sharma, Asst. prof., Dept. of CA & IT, SGRRITS, Dehradun

Create a statement object Statement st = k.createStatement( ); The connection class actually has two version of createStatement( ) the zero parameter version and two parameter version that supports the creation of Statement instances that generates Scrollable ResultSet objects. The default call translates to the following call: k.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); A TYPE_SCROLL_INSENSITIVE ResultSet is unware of in lace edits made to modifiable instances. TYPE_SCROLL_SENSITIVE, on the other hand, means that you can see changes made to the results if you scroll back to the modified row at later times Mr. Harish Sharma, Asst. prof., Dept. of CA & IT, SGRRITS, Dehradun

Mr. Harish Sharma, Asst. prof., Dept. of CA & IT, SGRRITS, Dehradun Execute a query String str = “select * from emp”;   ResultSet rs = st.executeQuery(str); Mr. Harish Sharma, Asst. prof., Dept. of CA & IT, SGRRITS, Dehradun

Mr. Harish Sharma, Asst. prof., Dept. of CA & IT, SGRRITS, Dehradun Process the ResultSet while ( rs.next()) { System.out.println(rs.getString(1) + “ ”+ rs.getString(2)); } Close the connection k.close( ); Connection to the database is closed. Mr. Harish Sharma, Asst. prof., Dept. of CA & IT, SGRRITS, Dehradun