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.

Slides:



Advertisements
Similar presentations
JDBC – Java DataBase Connectivity CSE432 Object Oriented Software Engineering.
Advertisements

Introduction to JDBC Standard framework for dealing with tabular and generally, relational data SQL (Structured Query Language) is standardized language.
JDBC. Java Database Connectivity (JDBC) Use the java.sql package to query and update the database. JDBC is an API that allows java to communicate with.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 32 Java Database.
JDBC Overview Autumn 2001 Lecturer: C. DeJong. Relational Databases widespread use used via SQL (Structured Query Language) freely available powerful.
1 C. Shahabi Application Programming for Relational Databases Cyrus Shahabi Computer Science Department University of Southern California
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.
1 Lecture 29 More on JDBC Overview  Objectives of this lecture  JDBC and its Drivers  Connecting to Databases (Java’s Connection class)  Querying a.
EmbeddedSQL: 1 Impedance Mismatch Problem Problem : How to connect SQL statements with conventional programming languages Different models of language.
CSE 190: Internet E-Commerce Lecture 13: Database code.
1 Foundations of Software Design Lecture 27: Java Database Programming Marti Hearst Fall 2002.
Introduction to JDBC (Java Database Connectivity).
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
Java Database Connectivity (JDBC) Francisco Pajaro Saul Acosta Nahum Quezada Manuel Rubio.
Helena Pomezná, ciz034 St. skupina: L392 FEI, VŠB-TUO Ak. rok. 2002/2003 Download:
Java Database Connectivity Vijayan Sugumaran Department of DIS Oakland University.
© Wang Bin 2004 JDBC ----Java Database Connectivity.
Beginning Databases with JDBC Mike Bradley Adapted from and notes by Kevin Parker, Ph.D.
Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.
Java Database Connectivity ASE. Java Database Connectivity (JDBC) l JDBC – provides an interface to Relational Data Sources l JDBC library provides the.
JDBC. JDBC Drivers JDBC is an alternative to ODBC and ADO that provides database access to programs written in Java.
MySQL, Java, and JDBC CSE 3330 Southern Methodist University.
JDBC (Java Database Connectivity) SNU OOPSLA Lab. October 2005.
12-CRS-0106 REVISED 8 FEB 2013 CSG2H3 Object Oriented Programming.
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.
JDBC. JDBC stands for Java Data Base Connectivity. JDBC is different from ODBC in that – JDBC is written in Java (hence is platform independent, object.
JDBC  The JDBC (Java Database Connectivity) API helps a Java program to access a database in a standard way  JDBC is a specification that tells the.
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.
JDBC Enterprise Systems Programming. JDBC  Java Database Connectivity  Database Access Interface provides access to a relational database (by allowing.
Chapter 8 Databases.
Accessing Database using JDBC. JDBC Objectives Gain basic knowledge of Java JDBC Become familiar with the basics of interacting with a database using.
COMP201 Java Programming Topic 15: Database Connectivity JDBC Reading: Chapter 4, Volume 2.
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.
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.
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.
Li Tak Sing COMPS311F. Database programming JDBC (Java Database Connectivity) Java version of ODBC (Open Database Connectivity) ODBC provides a standard.
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.
DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of.
JDBC™ Advanced Concepts
Access Databases from Java Programs via JDBC Tessema M. Mengistu Department of Computer Science Southern Illinois University Carbondale
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.
Umair Javed©2005 Enterprise Application Development Java Database Connectivity (JDBC) JDBC1.
JDBC I IS Why do we have databases?
6-1 JAVA DATABASE CONNECTOR Colorado Technical University IT420 Tim Peterson.
CS422 Principles of Database Systems JDBC and Embedded SQL Chengyu Sun California State University, Los Angeles.
Java and database. 3 Relational Databases A relational Database consists of a set of simple rectangular tables or relations The column headings are.
JDBC Statements The JDBC Statement, CallableStatement, and PreparedStatement interfaces define the methods and properties that enables to send SQL or PL/SQL.
JDBC – Java DataBase Connectivity
Lec - 14.
Course Outcomes of Advanced Java Programming AJP (17625, C603)
HW#4 Making Simple BBS Using JDBC
JDBC – Java DataBase Connectivity
JDBC – Java DataBase Connectivity
Objectives In this lesson, you will learn about:
Interacting with Database
JDBC – ODBC DRIVERS.
Java API for Database Connectivity
JDBC Example.
JDBC – Java DataBase Connectivity
Java Chapter 6 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

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 API for application writers Lower-level JDBC driver API for driver writers

In

Example Creating a database. Connecting to an ODBC data source. Inserting information into a database. Selectively retrieving information.

ProgrammerDay#cups GilbertMon1 WallyMon2 EdgarTue8 WallyTue2 EugeneTue2 JosephineWed2 EugeneThu3 GilbertThu1 ClarenceFri9 EdgarFri3 JosephineFri4

Load the JDBC-ODBC bridge Load a driver that tells the JDBC classes how to talk to a data source. In this case, you will need the class JdbcOdbcDriver: Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") This can also be specified from the command line via the jdbc.drivers system property: java -Djdbc.drivers=sun.jdbc.odbc.JdbcOdbcDriver

Connect to a Data Source Connection con = DriverManager.getConnection( URL, username, password) Where the username and password are empty strings, "", in this case because text files acting as ODBC data sources cannot have such attributes.

Send SQL Statements to Create the Table Statement stmt = con.createStatement(); Then, execute the following SQL statement to create a table called JoltData: create table JoltData ( programmer varchar (32), day char (3), cups integer, variety varchar (20));

Cont. The Java code to do this is: stmt.execute( "create table JoltData ("+ "programmer varchar (32),"+ "day char (3),"+ "cups integer);” ); Then, insert into JoltData values ('Gilbert', 'Mon', 1); insert into JoltData values ('Wally', 'Mon', 2); insert into JoltData values ('Edgar', 'Tue', 8);...

Content of “database” file "programmer","day","cups" "Gilbert","Mon",1 "Wally","Mon",2 "Edgar","Tue",8 "Wally","Tue",2 "Eugene","Tue",3 "Josephine","Wed",2 "Eugene","Thu",3 "Gilbert","Thu",1 "Clarence","Fri",9 "Edgar","Fri",3 "Josephine","Fri",4

Schema.ini JoltData] ColNameHeader=True CharacterSet=OEM Format=CSVDelimited Col1=programmer Char Width 32 Col2=day Char Width 3 Col3=cups Integer

Getting Information from a Database SELECT programmer, cups FROM JoltData ORDER BY cups DESC; From Java, execute the statement with: ResultSet result = stmt.executeQuery( "SELECT programmer, cups FROM JoltData ORDER BY cups DESC;");

Clarence9 Edgar8 Josephine4 Eugene3 3 Edgar3 Wally2 2 Josephine2 Gilbert1 1

Examine the ResultSet by 1."Moving" to the first row of data. result.next(); 2. Extracting data from the columns of that row. String name = result.getString("programmer"); int cups = result.getInt("cups"); The information can be printed easily via: System.out.println("Programmer "+name+ " consumed the most coffee: "+cups+" cups."); Resulting in the following output: Programmer Clarence consumed the most coffee: 9 cups.

Transactions Connection con = DriverManager.getConnection con.setAutoCommit(false); Statement s = con.createStatement(); s.executeUpdate("SQL statement 1"); s.executeUpdate("SQL statement 2"); s.executeUpdate("SQL statement 3"); con.commit();

Stored Procedures Statement stmt = con.createStatement(); Then execute the SQL statement: CREATE PROCEDURE int output AS BEGIN = sum (cups) FROM JoltData WHERE day END

Java Code stmt.execute ("CREATE PROCEDURE getDailyTotal " + int output " + "AS " + "BEGIN " + " = sum (cups) " + " FROM JoltData " + " WHERE day " + "END" );

CallableStatement CallableStatement cstmt = con.prepareCall ( "{call getDailyTotal (?, ?)}"); cstmt.setString (1, "Mon"); cstmt.registerOutParameter (2,java.sql.Types.INTEGER); cstmt.executeUpdate(); System.out.println ("Total is " + cstmt.getInt (2));