Java the UML Way versjon 2002-04-17 Only to be used in connection with the book "Java the UML Way", by Else Lervik and.

Slides:



Advertisements
Similar presentations
Java Database Connectivity (JDBC). 2/24 JDBC (Java DataBase Connectivity) - provides access to relational database systems JDBC is a vendor independent.
Advertisements

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.
Distributed Application Development B. Ramamurthy.
15-Jun-15 JDBC. JDBC is a Sun trademark It is often taken to stand for Java Database Connectivity Java is very standardized, but there are many versions.
19-Jun-15 SQL. SQL is Structured Query Language Some people pronounce SQL as “sequel” Other people insist that only “ess-cue-ell” is the only correct.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 32 Java Database.
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 Design patterns Lecture 4. 2 Three Important skills Understanding OO methodology Mastering Java language constructs Recognizing common problems and.
Java database Programming JDBC Trademarked name of a Java API that supports Java programs that access relational databases Stand for Java DataBase Connectivity.
Three-Tier Architecture Oracle DB Server Apache Tomcat App Server Microsoft Internet Explorer HTML Tuples HTTP Requests JDBC Requests Java Server Pages.
UFCE4Y UFCE4Y-20-3 Components and Services Julia Dawson.
JAVA JDBC JAVA JDBC Java Database Programming Lamiaa Said.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 37 Java Database Programming.
Lab: JDBC 1 Computer Engineering Lab III v Objective –to give some background on JDBC to help with the lab exercises , Semester 1,
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 the UML Way version Only to be used in connection with the book "Java the UML Way", by Else Lervik and.
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.
Java the UML Way versjon Only to be used in connection with the book "Java the UML Way", by Else Lervik and.
Overview of JDBC and Pro*C 1 Overview of JDBC,Pro*C and Oracle connectivity on Omega CSE 5330 – Database Systems.
Helena Pomezná, ciz034 St. skupina: L392 FEI, VŠB-TUO Ak. rok. 2002/2003 Download:
Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.
Java the UML Way versjon Only to be used in connection with the book "Java the UML Way", by Else Lervik and.
CIS 270—Application Development II Chapter 25—Accessing Databases with JDBC.
JDBC Tutorial MIE456 - Information Systems Infrastructure II Vinod Muthusamy November 4, 2004.
JDBC (Java Database Connectivity) SNU OOPSLA Lab. October 2005.
Java the UML Way versjon Only to be used in connection with the book "Java the UML Way", by Else Lervik and.
JDBC Java and Databases, including Postgress. JDBC l Developed by Industry leaders l Three main goals: –JDBC should be an SQL-level API –JDBC should capitalize.
Java the UML Way version Only to be used in connection with the book "Java the UML Way", by Else Lervik and.
Java the UML Way version Only to be used in connection with the book "Java the UML Way", by Else Lervik and.
Computer Engineering Lab
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.
Java the UML Way version Only to be used in connection with the book "Java the UML Way", by Else Lervik and.
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.
Accessing Database using JDBC. JDBC Objectives Gain basic knowledge of Java JDBC Become familiar with the basics of interacting with a database using.
JDBC – Java Database Concentricity
Chapter 25 Databases. Chapter Scope Database concepts Tables and queries SQL statements Managing data in a database Java Foundations, 3rd Edition, Lewis/DePasquale/Chase25.
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.
Java the UML Way version Only to be used in connection with the book "Java the UML Way", by Else Lervik and.
Copyright © 2002 ProsoftTraining. All rights reserved. Building Database Client Applications Using JDBC 2.0.
Java the UML Way versjon Only to be used in connection with the book "Java the UML Way", by Else Lervik and.
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.
Java the UML Way version Only to be used in connection with the book "Java the UML Way", by Else Lervik and.
Java and Databases. JDBC Architecture Java Application JDBC API Data Base Drivers AccessSQL Server DB2InformixMySQLSybase.
DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of.
DataBases and SQL INFSY 547 Spring Course Wrap Up April 12: Complete Work on Servlets Review of Team Projects Close of Portfolio Work April 19:
Java the UML Way version Only to be used in connection with the book "Java the UML Way", by Else Lervik and.
JDBC and SQLJ CIS 612 Spring JDBC JDBC is an API that enables database access from Java programs JDBC for DB access provides ◦ Portability across.
JDBC™ Fundamentals (a.k.a. Java Database Connectivity, although technically not an acronym) ©SoftMoore ConsultingSlide 1.
Java the UML Way versjon Only to be used in connection with the book "Java the UML Way", by Else Lervik and.
Access Databases from Java Programs via JDBC Tessema M. Mengistu Department of Computer Science Southern Illinois University Carbondale
Basics of JDBC.
Basics of JDBC Session 14.
JDBC (Java Database Connectivity)
1 Announcements Reading for next week: Chapters 6 and 7  Next-to-Last reading from the text for a little while (I promise) Your database accounts should.
Web Programming Assistant Professor Xiaozhong Liu
Introduction to JDBC Instructor: Mohamed Eltabakh 1.
In the Name Of Almighty Allah. Java Application Connection To Mysql Created by Hasibullah (Sahibzada) Kabul Computer Science Faculty Afghanistan.
Using Oracle JDBC How to Run JDBC on Your Account Communication Mechanism Using Metadata Building a Database Auto Commit v.s Atomic Transaction.
JDBC. Database is used to store data permanently. These days almost all Applications needs database to store its data persistently. Below are the most.
1. Writing a Java program to connect to SQL Server 2008 and Create a table Populate the table (insert data) Perform queries to retrieve information from.
JDBC 15-Apr-18.
JDBC 21-Aug-18.
JDBC 15-Nov-18.
Interacting with Database
Java API for Database Connectivity
Presentation transcript:

Java the UML Way versjon Only to be used in connection with the book "Java the UML Way", by Else Lervik and Vegard B. Havdal. ISBN , John Wiley & Sons Ltd 2002 The Research Foundation TISIP, Chapter 20 Programming with Databases What is JDBC?page 2 Database driverspage 3 The example Databasepage 4 Establishing database contactpage 5 The relationship between SQL data types, Java data types and getxxx() methodspage 6 A bigger examplepage 7 A database applicationpage 8 The three-layer architecturepage 9 Transactionspage 10 Compiled SQL statementspage 11

Only to be used in connection with the book "Java the UML Way", by Else Lervik and Vegard B. Havdal. ISBN , John Wiley & Sons Ltd 2002 The Research Foundation TISIP, Chapter 20, page 2 What is Java Database Connectivity (JDBC)? JDBC is –not a database system, but makes communication with a database system possible –not a ”point and click, drag and drop” tool, such as Microsoft Access, but it may be used by the developers of such tools to communicate with the database. JDBC is an API offering classes that makes it possible to send SQL statements to a database, and to interpret the results from the statements. This chapter assumes that you are familiar with relational databases and SQL.

Only to be used in connection with the book "Java the UML Way", by Else Lervik and Vegard B. Havdal. ISBN , John Wiley & Sons Ltd 2002 The Research Foundation TISIP, Chapter 20, page 3 Database Drivers A database driver consists of classes that implement certain interfaces. JDBC Driver Manager JDBC-ODBC Bridge ODBC Driver Microsoft Access Microsoft SQL Server Oracle Database Sybase Database Oracle DriverSybase Driver Java application Java application Java application

Only to be used in connection with the book "Java the UML Way", by Else Lervik and Vegard B. Havdal. ISBN , John Wiley & Sons Ltd 2002 The Research Foundation TISIP, Chapter 20, page 4 The Example Database create table person( identno integer primary key, firstname varchar(30) not null, lastname varchar(30) not null); insert into person values (100, 'EDWARD', 'BROWN'); insert into person values (101, 'ANN MARGARET', 'GREEN'); insert into person values (102, 'JOHN', 'JOHNSON'); identnofirstnamelastname 100 EDWARDBROWN 101ANN MARGARETGREEN 102JOHNJOHNSON

Only to be used in connection with the book "Java the UML Way", by Else Lervik and Vegard B. Havdal. ISBN , John Wiley & Sons Ltd 2002 The Research Foundation TISIP, Chapter 20, page 5 A Little Program Communicating With the Database import javax.swing.*; import java.sql.*; class DatabaseContact { public static void main(String[] args) throws Exception { String databaseDriver = "oracle.jdbc.driver.OracleDriver"; Class.forName(databaseDriver); String userName = JOptionPane.showInputDialog("User Name: "); String password = JOptionPane.showInputDialog("Password: "); String databaseName = Connection conn = DriverManager.getConnection(databaseName, userName, password); Statement statement = conn.createStatement(); ResultSet res = statement.executeQuery("select * from person"); while (res.next()) { int idNo = res.getInt("identNo"); String firstName = res.getString("firstname"); String lastName = res.getString("lastname"); System.out.println(idNo + ": " + firstName + " " + lastName); } res.close(); statement.close(); conn.close(); System.exit(0); } Our database driver is the classes111.zip file. C LASSPATH has to contain classes111.zip. This file contains, among other things oracle.jdbc.driver.OracleDriver.

Only to be used in connection with the book "Java the UML Way", by Else Lervik and Vegard B. Havdal. ISBN , John Wiley & Sons Ltd 2002 The Research Foundation TISIP, Chapter 20, page 6 The Relationship Between SQL Data Type, Java Data Types, and getxxx() Methods CHAR, VARCHAR, LONGVARCHARStringgetString() NUMERIC, DECIMALjava.math.BigDecimalgetBigDecimal() BITbooleangetBoolean() TINYINTbytegetByte() SMALLINTshortgetShort() INTEGERintgetInt() BIGINTlonggetLong() REALfloatgetFloat() FLOAT, DOUBLEdoublegetDouble() BINARY, VARBINARY, LONGVARBINARYbyte[]getBytes() DATEjava.sql.DategetDate() TIMEjava.sql.TimegetTime() TIMESTAMPjava.sql.TimestampgetTimestamp()

Only to be used in connection with the book "Java the UML Way", by Else Lervik and Vegard B. Havdal. ISBN , John Wiley & Sons Ltd 2002 The Research Foundation TISIP, Chapter 20, page 7 A Bigger Example Show program listing 20.2, pp Database getAll() updateName(thePerson: Person) registerNewPerson(firstName: String, lastName: String) deletePerson(identNo: int) closeTheConnection()

Only to be used in connection with the book "Java the UML Way", by Else Lervik and Vegard B. Havdal. ISBN , John Wiley & Sons Ltd 2002 The Research Foundation TISIP, Chapter 20, page 8 A Database Application Show program listing 20.3, pp

Only to be used in connection with the book "Java the UML Way", by Else Lervik and Vegard B. Havdal. ISBN , John Wiley & Sons Ltd 2002 The Research Foundation TISIP, Chapter 20, page 9 The Three-Layer Architecture 1. The physical database 2. The component which communicates with the database 3. The user interface component which communicates with the component above. Solve the problems, page 641.

Only to be used in connection with the book "Java the UML Way", by Else Lervik and Vegard B. Havdal. ISBN , John Wiley & Sons Ltd 2002 The Research Foundation TISIP, Chapter 20, page 10 Transactions A transaction is a logical unit of work and can consist of multiple update statements to the database. For example, if money is going to be transferred from one account to another, it’s important that the balances in both of the accounts change. If an error occurs, we can’t risk that only one of the accounts changes its balance. This transaction consists of two update statements. The transaction is worked out in a correct way: Commit! The transaction is not worked out in a correct way: Rollback! As default, every single SQL statement is a transaction unit. The Connection interface let us create transactions consisting of more than one SQL statement. –public void setAutoCommit(boolean autocommit) // default is true –public void commit() –public void rollback() Solve problem 1, page 645.

Only to be used in connection with the book "Java the UML Way", by Else Lervik and Vegard B. Havdal. ISBN , John Wiley & Sons Ltd 2002 The Research Foundation TISIP, Chapter 20, page 11 Compiled SQL Statements The Java interpreter sends the SQL statement to the database system. The database system sets up a plan so that the search can be done in the most efficient way possible. Unnecessary to compile again if only literals are changed: –select * from person where firstName like ’ANNE’ and lastName like ’GREEN’; –select * from person where firstName like ’JOHN’ and lastName like ’JOHNSON’; The PreparedStatement interface let us create precompiled statement objects. An example: String sqlStatement = "select * from person where firstName like ? and lastName like ?"; PreparedStatement statement = conn.prepareStatement(sqlStatement); setning.setString(1, ”ANNE”); // The search criteria may be input, setning.setString(2, ”GREEN”); // see program listing 20.4 pp ResultSet res = statement.executeQuery(); while (res.next()) { …osv….