Java Programming: JDBC Vyacheslav Grebenyuk CTDE, AI dept., KhNURE.

Slides:



Advertisements
Similar presentations
Copyright  Oracle Corporation, All rights reserved. 2 Java and Databases: An Overview.
Advertisements

JDBC CS-328. JDBC Java API for accessing RDBMS Allows use of SQL for RDBMS programming Can be used for: –embedded SQL –execution of stored queries.
1 JDBC: Part I Attribution These slides are based on three primary sources: –Sun JDBC Tutorial URL: jdbc/TOC.htmlhttp://java.sun.com/docs/books/tutorial/
JDBC Overview Autumn 2001 Lecturer: C. DeJong. Relational Databases widespread use used via SQL (Structured Query Language) freely available powerful.
Java Database Connectivity (JDBC) java.sql package to query and update the database. JDBC is an API that allows java to communicate with a database server.
EmbeddedSQL: 1 Impedance Mismatch Problem Problem : How to connect SQL statements with conventional programming languages Different models of language.
Java Database Connectivity JDBC  JDBC is an API, containing classes and interfaces in the java programming language, to execute SQL sentences over an.
Session-01. Hibernate Framework ? Why we use Hibernate ?
Welcome to the JSON-stores world Learning & Development Telerik Software Academy.
JDBC / ODBC JDBC is the java API that facilitate interaction of a java application with the DBMS. FIRST APPROACH:
Getting connected.  Java application calls the JDBC library.  JDBC loads a driver which talks to the database.  We can change database engines without.
1 CSC 440 Database Management Systems JDBC This presentation uses slides and lecture notes available from
Java Database Connectivity (JDBC) Francisco Pajaro Saul Acosta Nahum Quezada Manuel Rubio.
Database Management Systems 1 Oracle Programming.
JDBC. What is JDBC JDBC is an acronym for –Java Data Base Connectivity. It allows java/jsp program to connect to any database.
MySQL, Java, and JDBC CSE 3330 Southern Methodist University.
JDBC (Java Database Connectivity) SNU OOPSLA Lab. October 2005.
Connecting to Oracle using Java November 4, 2009 David Goldschmidt, Ph.D. David Goldschmidt, Ph.D.
Java + XML. Java 2 Enterprise Edition Server Side java Servlets JSP JavaBeans Web Services Database jdbc.
Introduction to JDBC Michelle Lee, Ye Wu & Jeff Offutt SWE 432 Design and Implementation of Software for the Web.
Ant Ant2 Призначення: виконання повторюваних, як правило, рутинних завдань, пов'язаних із розробкою, розгортанням, виконанням проектів. Приклади.
JDBC – Java DataBase Connectivity. JDBC API Overview JDBC is Java API that allows the Java programmers to access database management system from Java.
JDBC. Preliminaries Database Database Collection of data Collection of data DBMS DBMS Database management system Database management system Stores and.
Chapter 8 Databases.
COMP201 Java Programming Topic 15: Database Connectivity JDBC Reading: Chapter 4, Volume 2.
Chapter 25 Databases. Chapter Scope Database concepts Tables and queries SQL statements Managing data in a database Java Foundations, 3rd Edition, Lewis/DePasquale/Chase25.
JDBC Establish a connection with a database or access any tabular data source Send SQL statements Process the results Two major sets of interfaces: JDBC.
Java Database Connectivity. Java and the database Database is used to store data. It is also known as persistent storage as the data is stored and can.
JDBC Database Programming in Java Prepared by., Mrs.S.Amudha AP/SWE.
Java and Databases. JDBC Architecture Java Application JDBC API Data Base Drivers AccessSQL Server DB2InformixMySQLSybase.
COMP 321 Week 4. Overview Normalization Entity-Relationship Diagrams SQL JDBC/JDBC Drivers hsqldb Lab 4-1 Introduction.
UNIT III - JDBC JDBC Overview – JDBC implementation – Connection class – Statements - Catching Database Results, handling database Queries. Networking–
DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of.
Tasks Needed for MissionMapEditor Martin Q. Zhao September 18, 2010.
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.
Basics of JDBC Session 14.
JDBC (Java Database Connectivity)
JDBC Java DataBase Connectivity. Loading the driver import java.sql.*... Class.forName("org.postgresql.Driver")‏
Advanced Java Session 5 New York University School of Continuing and Professional Studies.
Web Programming Assistant Professor Xiaozhong Liu
In the Name Of Almighty Allah. Java Application Connection To Mysql Created by Hasibullah (Sahibzada) Kabul Computer Science Faculty Afghanistan.
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.
JDBC. Database is used to store data permanently. These days almost all Applications needs database to store its data persistently. Below are the most.
SaaS Cloud Platform Providing Database Access Through RESTful API Learning & Development Telerik Software Academy.
1 Copyright 2007 MySQL AB The World’s Most Popular Open Source Database MySQL Proxy WebTech 2007 Варна, България 29-ти Юни 2007 Aндрей Христов.
Java Programming: Interfaces and Packages Vyacheslav Grebenyuk CTDE, AI dept., KhNURE.
JSP and DB.
CS JDBC.
Database: JDBC Overview
Interacting with Database
Course Outcomes of Advanced Java Programming AJP (17625, C603)
JDBC & Servlet CSE 4504/6504 Lab.
Database JDBC Overview CS Programming Languages for Web Applications
Advanced Web Automation Using Selenium
HW#4 Making Simple BBS Using JDBC
Design and Implementation of Software for the Web
JDBC – Java DataBase Connectivity
Client Access, Queries, Stored Procedures, JDBC
Objectives In this lesson, you will learn about:
Mr. Harish Sharma Asst. Professor Dept. of CA & IT SGRRITS Dehradun
Interacting with Database
JDBC – ODBC DRIVERS.
MSIS 655 Advanced Business Applications Programming
Using a Database with JDBC
ODBC and JDBC.
JDBC Example.
Storing and Processing Sensor Networks Data in Public Clouds
Java Database Connectivity JDBC
Presentation transcript:

Java Programming: JDBC Vyacheslav Grebenyuk CTDE, AI dept., KhNURE

(С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, Content

(С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, /30/2016 JDBC JDBC (Java Database Connectivity) API allows Java programs to connect to databases Database access is the same for all database vendors The JVM uses a JDBC driver to translate generalized JDBC calls into vendor specific database calls There are four general types of JDBC drivers  We will look at Type 4 …

(С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, /30/2016 Pure Java Driver (Type 4) These drivers convert the JDBC API calls to direct network calls using vendor-specific networking protocols by making direct socket connections with the database It is the most efficient method to access database, both in performance and development time It is the simplest to deploy All major database vendors provide pure Java JDBC drivers for their databases and they are also available from third party vendors For a list of JDBC drivers, refer to 

(С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, /30/2016 Java Application DB Client Pure Java Driver (2) JDBC API JDBC Driver Data Source Server

(С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, /30/2016 Typical JDBC Programming Procedure 1. Load the database driver 2. Obtain a connection 3. Create and execute statements (SQL queries) 4. Use result sets (tables) to navigate through the results 5. Close the connection

(С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, /30/2016 Driver Manager The purpose of the java.sql.DriverManger class in JDBC is to provide a common access layer on top of different database drivers used in an application DriverManager requires that each driver required by the application must be registered before use, so that the DriverManager is aware of it Load the database driver using ClassLoader :  Class.forName (“oracle.jdbc.driver.OracleDriver”);

(С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, /30/2016 Connecting to a Database Type 4 JDBC Driver – Oracle Server Class.forName (“oracle.jdbc.driver.OracleDriver”); con = DriverManager.getConnection ( “accountname", “password”); Type 4 JDBC Driver – MySQL Server Class.forName (“org.gjt.mm.mysql.Driver”); con = DriverManager.getConnection (“jdbc:mysql://localhost/databasename”, uid, passwd);

(С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, /30/2016 Creating Tables Creating a Coffee table CREATE TABLE COFFEES (COF_NAME VARCHAR(32), SUP_ID INTEGER, PRICE FLOAT, SALES INTEGER, TOTAL INTEGER) Creating JDBC statements Statement stmt = con.createStatement (); Execute a statement stmt.executeUpdate (“CREATE TABLE COFFEES “ + “(COF_NAME VARCHAR(32), SUP_ID INTEGER, PRICE FLOAT, “ + “SALES INTEGER, TOTAL INTEGER)”); SQL query

(С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, /30/2016 Execute Statements This uses executeUpdate because the SQL statement contained in createTableCoffees is a DDL (data definition language) statement Statements that create a table, alter a table, or drop a table are all examples of DDL statements and are executed with the method executeUpdate executeUpdate is also used to execute SQL statements that update a table

(С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, /30/2016 Execute Statements In practice, executeUpdate is used far more often to update tables than it is to create them because a table is created once but may be updated many times The method used most often for executing SQL statements is executeQuery executeQuery is used to execute SELECT statements, which comprise the vast majority of SQL statements

(С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, /30/2016 Entering Data into a Table Statement stmt = con.createStatement(); stmt.executeUpdate ( "INSERT INTO COFFEES " + "VALUES ('Colombian', 101, 7.99, 0, 0)" ); stmt.executeUpdate ( "INSERT INTO COFFEES " + "VALUES ('French_Roast', 49, 8.99, 0, 0)" ); stmt.executeUpdate ( "INSERT INTO COFFEES " + "VALUES ('Espresso', 150, 9.99, 0, 0)" ); stmt.executeUpdate ( "INSERT INTO COFFEES " + "VALUES ('Colombian_Decaf', 101, 8.99, 0, 0)" ); stmt.executeUpdate ( "INSERT INTO COFFEES " + "VALUES ('French_Roast_Decaf', 49, 9.99, 0, 0)" );

(С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, /30/2016 Getting Data From a Table ResultSet rs = stmt.executeQuery ("SELECT COF_NAME, PRICE FROM COFFEES"); while (rs.next()) { String s = rs.getString ("COF_NAME"); float n = rs.getFloat ("PRICE"); System.out.println (s + " " + n); }

(С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, /30/2016 JNDI Connection Manager JDBC Data Source Architecture Application JDBC Database

(С) ЦТДО, каф. Искусственного интеллекта, ХНУРЭ, Instead of conclusion