Beginning Databases with JDBC Mike Bradley Adapted from and notes by Kevin Parker, Ph.D.

Slides:



Advertisements
Similar presentations
CE203 - Application Programming Autumn 2013CE203 Part 51 Part 5.
Advertisements

Murach’s Java SE 6, C21© 2007, Mike Murach & Associates, Inc.Slide 1.
1 JDBC Java Database Connectivity. 2 c.pdf
JDBC Overview Autumn 2001 Lecturer: C. DeJong. Relational Databases widespread use used via SQL (Structured Query Language) freely available powerful.
Java Database Connectivity By: Abe Marji CS616. Agenda 1.Quick Review of Databases 2.What is SQL? 3.What is JDBC? 4.Advanced Functions of JDBC 5.Summary.
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.
CSE470 Software Engineering Fall Database Access through Java.
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. –
Java Database Connectivity (JDBC) Francisco Pajaro Saul Acosta Nahum Quezada Manuel Rubio.
Think Possibility Integrating Web Applications With Databases.
Helena Pomezná, ciz034 St. skupina: L392 FEI, VŠB-TUO Ak. rok. 2002/2003 Download:
CSCI 6962: Server-side Design and Programming JDBC Database Programming.
CS178 Database Management “JDBC”. What is JDBC ? JDBC stands for “Java DataBase Connectivity” The standard interface for communication between a Java.
Java Database Connectivity Vijayan Sugumaran Department of DIS Oakland University.
JDBC. What is JDBC JDBC is an acronym for –Java Data Base Connectivity. It allows java/jsp program to connect to any database.
© Wang Bin 2004 JDBC ----Java Database Connectivity.
CSE470 Software Engineering Fall Database Access through Java.
Database Programming in Java Corresponds with Chapter 32, 33.
Java Utility Classes CS 21b. Some Java Utility Classes Vector Hashtable StringTokenizer * import java.util.*;
Active Server Pages ASP is Microsoft’s server-side script engine for dynamically-generated web pages. Most common language used is VBScript. If you use.
JDBC Tutorial MIE456 - Information Systems Infrastructure II Vinod Muthusamy November 4, 2004.
JDBC (Java Database Connectivity) SNU OOPSLA Lab. October 2005.
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui COMP 302 Database Systems Java Data Base Connectivity Lecturer Dr Pavle Mogin.
CS 405G: Introduction to Database Systems Database programming.
Java + XML. Java 2 Enterprise Edition Server Side java Servlets JSP JavaBeans Web Services Database jdbc.
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.
MIS 3023 Business Programming II Professor: Akhilesh Bajaj Introduction to JDBC © Akhilesh Bajaj, All Rights Reserved.
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.
Copyright  Oracle Corporation, All rights reserved. 6 Accessing a Database Using the JDBC API.
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.
Copyright © 2002 ProsoftTraining. All rights reserved. Building Database Client Applications Using JDBC 2.0.
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.
UNIT III - JDBC JDBC Overview – JDBC implementation – Connection class – Statements - Catching Database Results, handling database Queries. Networking–
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
JDBC (Java Database Connectivity)
Advanced Java Session 5 New York University School of Continuing and Professional Studies.
Database Programming With Java & JDBC Reading: DD Ch. 18, pp al/jdbc/index.html, or anything covering JDBC.
Umair Javed©2005 Enterprise Application Development Java Database Connectivity (JDBC) JDBC1.
1 JDBC – Java Database Connectivity CS , Spring 2010.
Intro to JDBC Joseph Sant Applied Computing and Engineering Sciences Sheridan ITAL.
6-1 JAVA DATABASE CONNECTOR Colorado Technical University IT420 Tim Peterson.
JSP/Database Connectivity Instructor: Dr. M. Anwar Hossain.
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.
CS320 Web and Internet Programming Database Access with JDBC Chengyu Sun California State University, Los Angeles.
DEPTT. OF COMP. SC & APPLICATIONS
Lec - 14.
JDBC – Java Database Connectivity
HW#4 Making Simple BBS Using JDBC
Client Access, Queries, Stored Procedures, JDBC
Introduction to Server-Side Web Development using JSP and Databases
Objectives In this lesson, you will learn about:
Interacting with Database
JDBC Example.
Java Chapter 6 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

Beginning Databases with JDBC Mike Bradley Adapted from and notes by Kevin Parker, Ph.D.

Overview Getting Started Setting Up a Database Establishing a Connection Creating Statements Executing Statements Retrieving Values from Result Sets Updating Tables Intermediate JDBC

Getting Started Things you need installed Java and JDBC  Get the latest JDK at Database drivers  Can be supplied by the vendor  JDBC-ODBC bridge is installed automatically with JDK for Windows and Solaris Database Management System  If needed, not necessary for some databases, such as Microsoft Access

Setting Up a Database JDBC allows for Connections to a database Sending SQL commands to the database Receiving responses from the database Things to remember Must have access to proper library  Import java.sql.* Objects must be in methods that can throw exceptions, or try..catch blocks to catch ClassNotFoundException and SQLException

Establishing a Connection Establishing a connection consists of two steps Loading drivers  Class.forName(“jdbc.DriverName”);  Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver” ); Making the connection  Connection con = DriverManager.getConnection(url, “myLogin”, “myPassword”)

Establishing a Connection: The URL What to put in the URL Documentation for the driver should indicate what to put after the jdbc: For the JDBC-ODBC bridge it will be jdbc:odbc:something  Something can be a DSN, or connection string information jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=C:/comic.mdb Jdbc:odbc:Driver={SQL Server};Server=SERVERNAME;UID=user;PWD=pass;datab ase=DATABASENAME

Creating Statements Statement objects send SQL commands to the database Statements require an active Connection object to be created Statement stmt = con.createStatement();

Executing Statements Three types of statements to execute Queries Data updates Data definition language (DDL) statements Called with stmt.executeXXX executeQuery(“SQL statement”) for returning ResultSet executeUpdate(“SQL statement”) for data updates and DDL statements

Retrieving Values from Result Sets Creating a result set ResultSet rs = stmt.executeQuery(someQuery) Using next method Initially the cursor for the RecordSet is prior to the first record rs.next() moves the cursor to the record in the record set

Retrieving (cont.) Using the rs.getXXX() methods getXXX methods exist for most primitive data types and some common objects (String, Date, Object) Can take either String or int parameter  String parameter is the field (column) name String s = rs.getString(“IssueName”);  Int parameter is the 1-based ordinal number of the field String s = rs.getString(3);

Updating Tables Uses executeQuery(someQuery) Used for data updates and DDL statements INSERT, UPDATE, and DELETE CREATE TABLE Can either get return value or ignore it int n = stmt.executeQuery(“UPDATE foo SET bar = 1 WHERE snafu = ‘tarfu’”) n will equal the number of rows affected  DDL statements always return 0

Intermediate JDBC Prepared Statements Similar to normal statements, but query is supplied during creation, and can contain parameter values Transactions For processing all or nothing batch updates Stored Procedures For calling procedures which exist in the DBMS rather than supplied in code

Summary JDBC is very similar to working with databases in.NET or other OO and OB languages Syntax is most difficult thing Remember to catch or throw errors