MC365 JDBC and Server-Side Programming: Updating a database via JDBC & Connection Pooling.

Slides:



Advertisements
Similar presentations
Basic JDBC Celsina Bignoli What is JDBC Industry standard for database- connectivity between the Java language and a wide range of.
Advertisements

Database programming in Java An introduction to Java Database Connectivity (JDBC)
1 JDBC Java Database Connectivity. 2 c.pdf
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.
MC365 JDBC in Servlets. Today We Will Cover: DBVisualizer Using JDBC in servlets Using properties files.
Java MS Access database connectivity Follow these steps: 1)Go to the start->Control Panel->Administrative Tools- > data sources. 2)Click Add button and.
SEMESTER 1, 2013/2014 DB2 APPLICATION DEVELOPMENT OVERVIEW.
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.
Java Database Connectivity (JDBC). Introduction Database –Collection of data DBMS –Database management system –Storing and organizing data SQL –Relational.
Database Processing with JSP ISYS 350. Example: Enter CID in a box and retrieve the customer record.
Think Possibility Integrating Web Applications With Databases.
CSCI 6962: Server-side Design and Programming JDBC Database Programming.
Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.
Database Processing with JSP ISYS 350. Example: Enter CID in a box and retrieve the customer record.
CONTROLPANEL Java.sql package This package provides the APIs for accessing and processing data which is stored in the database especially relational.
Connecting to Oracle using Java November 4, 2009 David Goldschmidt, Ph.D. David Goldschmidt, Ph.D.
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.
Stored procedures1 Stored procedures and functions Procedures and functions stored in the database.
CS 160: Software Engineering October 1 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
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.
1 JDBC Aum Amriteshwaryai Namah. 2 2 JDBC – Java DataBase Connectivity.
Accessing Your MySQL Database from the Web with PHP (Ch 11) 1.
JDBC Enterprise Systems Programming. JDBC  Java Database Connectivity  Database Access Interface provides access to a relational database (by allowing.
WEB/DB1 DATABASE PROGRAMMING 3JDBC by the ASU Scholars.
Copyright © 2002 ProsoftTraining. All rights reserved. Building Database Client Applications Using JDBC 2.0.
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.
Database Processing with JSP ISYS 350. Example: Enter CID in a box and retrieve the customer record.
JDBC CS 260 Database Systems. Overview  Introduction  JDBC driver types  Eclipse project setup  Programming with JDBC  Prepared statements  SQL.
DAT602 Database Application Development Lecture 8 Advanced JDBC.
SQlite. SQLite is a opensource SQL database that stores data to a text file on a device. Android comes in with built in SQLite database implementation.
Basics of JDBC Session 14.
SCU Fall 2002JoAnne Holliday10–1 Schedule Today u Triggers, Procedures, PL/SQL. u Read Sections , 8.1, 8.5. Next u Transaction concepts, security.
Ch. NoNameMarks 01AWT24 02Networking18 03JDBC20 04Swing18 05Servlet20 Advance Java Programming.
Database Programming With Java & JDBC Reading: DD Ch. 18, pp al/jdbc/index.html, or anything covering JDBC.
1 Principles of Database Systems With Internet and Java Applications Today’s Topic Chapter 8: Applications Programming for Relational Databases Instructor’s.
Database Processing with JSP ISYS 350. Example: Enter CID in a box and retrieve the customer record.
JDBC Java and Databases. SWC – JDBC JDBC – Java DataBase Connectivity An API (i.e. a set of classes and methods), for working with databases in.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Java Database Connectivity.
1 JDBC – Java Database Connectivity CS , Spring 2010.
Intro to JDBC Joseph Sant Applied Computing and Engineering Sciences Sheridan ITAL.
Chapter 7 Chapter 7 Java Database Connectivity using JSP 1 (IS 203) WebProgramming (IS 203) Web Programming.
JDBC Statements The JDBC Statement, CallableStatement, and PreparedStatement interfaces define the methods and properties that enables to send SQL or PL/SQL.
JDBC. What is JDBC JDBC is an acronym for –Java Data Base Connectivity. It allows java program to connect to any database.
JDBC. Database is used to store data permanently. These days almost all Applications needs database to store its data persistently. Below are the most.
Database Processing with JSP ISYS 350. Database Applications Applications Database Server Queries/Updates Results.
A Presentation Presentation On JSP On JSP & Online Shopping Cart Online Shopping Cart.
CS320 Web and Internet Programming Database Access with JDBC Chengyu Sun California State University, Los Angeles.
JDBC III IS Outline  Scrollable ResultSets  Updatable ResultSets  Prepared statements  Stored procedures.
Database: JDBC Overview
DEPTT. OF COMP. SC & APPLICATIONS
CS3220 Web and Internet Programming Database Access with JDBC
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.
JDBC 15-Apr-18.
JDBC – Java Database Connectivity
JDBC III IS
CS320 Web and Internet Programming Database Access with JDBC
Database JDBC Overview CS Programming Languages for Web Applications
JDBC 21-Aug-18.
JDBC 15-Nov-18.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
Bolat Azamat, Kim Dongmin
JDBC Example.
CS3220 Web and Internet Programming Database Access with JDBC
CS3220 Web and Internet Programming Database Access with JDBC
Presentation transcript:

MC365 JDBC and Server-Side Programming: Updating a database via JDBC & Connection Pooling

Today We Will Cover: Prepared Statements Performing Updates and Inserts in JDBC Connection Pooling Stored Procedures

Prepared Statements –A PreparedStatement is a subinterface of Statement that offers several benefits:PreparedStatement The contained SQL is sent to the database and compiled or prepared beforehand. From this point on, the prepared SQL is sent and this step is bypassed. The more dynamic Statement requires this step on every execution. Depending on the DB engine, the SQL may be cached and reused even for a different PreparedStatement and most of the work is done by the DB engine rather than the driver. –A PreparedStatement can take IN parameters, which act much like arguments to a method, for column values. –PreparedStatements deal with data conversions that can be error prone in straight ahead, built on the fly SQL; handling quotes and dates in a manner transparent to the developer, for example.

JDBC Updates and Inserts Must use executeUpdate method instead of executeQuery for inserts, updates and deletes –executeUpdate() returns an int containing the affected row count for INSERT, UPDATE, or DELETE statements, or zero for SQL statements that do not return anything. Example of a JDBC Update Notes/JDBCUpdate.java Notes/JDBCUpdate.java Example of a JDBC Insert Notes/JDBCInsert.java Notes/JDBCInsert.java Checking for nulls from a Select –To do this simply check the ResultSet for null after performing a Select statement.

Connection Pooling What is connection pooling? –Connection pooling is a technique used for managing server resources. The program does this by making a limited set of connections to the database. –Clients or servlets go through this connection pool to get a connection to the database. –The connection pool class manages connections that are in use and ones that are available. Why do we use it? –Connecting to a database is one of the most resource-intensive processes. It can take a long time and really slow down your server if a large number of connections are made. In fact, it can even stall your server. –The biggest benefit of connection pooling is that it creates the connections in advance. –When a servlet needs a connection, it is already available. This is much more efficient than having each servlet make its own connection. –In addition, it limits the number of connections made to the db. Many servlets can share a small set of connections because once they use the connection, they can release it fairly quickly.

Connection Pooling Some app servers have built-in connection pooling. You can also write your own or find shareware code online. Here is an example of a class that manages connection pooling that you can use: Notes/ConnectionPool.java Notes/ConnectionPool.java Here is an example of a servlet using this ConnectionPool class: Notes/ConnectionPoolServlet.java Notes/ConnectionPoolServlet.java

Stored Procedures What are they? –These are basically SQL statements, or a set of SQL statements, that are stored directly on the database. Why do we use them? –Offers a lot more flexibility. –Leaves the SQL coding the DBA. This is a true separation of the data layer. –Even more efficient. Examples Notes/SQLExamples.doc Notes/SQLExamples.doc