1 JDBC Resource Registration on WebSphere Console javax.naming.InitialContext ctx = new javax.naming.InitialContext(); javax.sql.DataSource ds = (javax.sql.DataSource)ctx.lookup("jdbc/DB2UDB");

Slides:



Advertisements
Similar presentations
21 Copyright © 2005, Oracle. All rights reserved. Oracle Application Server 10g Transaction Support.
Advertisements

5 Copyright © 2005, Oracle. All rights reserved. Accessing the Database with Servlets.
16 Copyright © 2005, Oracle. All rights reserved. Using JDBC to Access the Database.
Distributed Transactions in Java EE Nikolai Tankov SAP Labs Bulgaria January 19th, 2008 Sofia, Bulgaria.
19 augustus 2003augustus 2003 JSP-2. BICT 2JDBC BICT 3Install MySQL Download MySQL daemon – Free – Windows version… Start Daemon – Mysqld-nt.exe Download.
Basic JDBC Celsina Bignoli What is JDBC Industry standard for database- connectivity between the Java language and a wide range of.
Database programming in Java An introduction to Java Database Connectivity (JDBC)
Java web hosting at CERN Computing Seminar, 1 November 2005 Michał Kwiatek, IT-DES.
1 CSE5200 JDBC and JDeveloper JDBC java.sql package java.sql classes.
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.
1 Lecture 05: Database Programming (JDBC). 2 Outline JDBC overview JDBC API Reading: Chapter 10.5 Pointbase Developer Manual.
Advanced Java Programming – Eran Toch Methodologies in Information System Development Tutorial: Advanced Java Programming and Database connection Eran.
JDBC Data source and Connection pooling 1 JDBC Data sources and Connection pooling.
Three-Tier Architecture Oracle DB Server Apache Tomcat App Server Microsoft Internet Explorer HTML Tuples HTTP Requests JDBC Requests Java Server Pages.
Basic JDBC Use Oracle JDBC Drivers must be in the CLASSPATH
Figure 1–3 Family Tree for RDF Example (see Monday October, 10 link - Oracle Semantic Tutorial examples on 1-28 and 1-29)Oracle Semantic Tutorial examples.
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.
Overview of JDBC and Pro*C 1 Overview of JDBC,Pro*C and Oracle connectivity on Omega CSE 5330 – Database Systems.
JDBC. What is JDBC JDBC is an acronym for –Java Data Base Connectivity. It allows java/jsp program to connect to any database.
1 The JNDI ENC and Injection Every EJB container that is deployed in an application server has its own personal internal registry called the Enterprise.
Javax.sql and java.sql. java.sql Interface Connection public interface Connection extends WrapperWrapper A connection (session) with a specific database.
© jGuru.com EJB Transactions. Transactions Simple Transaction –Transaction = more than one statement which must all succeed (or all fail) together.
JDBC Session 3 Tonight’s topics: 1.Connection Pooling 2.Transaction Processing Redux 3.Distributed Transactions 4.RowSets 5.Yet more lab time! (Design.
Enterprise JavaBeans EJB Container Services. EJB container Enterprise JavaBeans are deployed in an EJB container within the application server EJB container.
Java Transaction API Sean C. Sullivan
MySQL, Java, and JDBC CSE 3330 Southern Methodist University.
JDBC Tutorial MIE456 - Information Systems Infrastructure II Vinod Muthusamy November 4, 2004.
JDBC (Java Database Connectivity) SNU OOPSLA Lab. October 2005.
JAVA Database Access. JDBC The Java Database Connectivity (JDBC) API is the industry standard for database- independent connectivity between the Java.
CS 405G: Introduction to Database Systems Database programming.
Overview of JDBC and Pro*C 1 CSE 5330 – Database Systems.
Servlets Database Access. Agenda:  Setup Java Environment  Install Database  Install Database Drivers  Create Table and add records  Accessing a.
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.
Copyright  Oracle Corporation, All rights reserved. 4 Accessing a Database Using JBCL.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Copyright  Oracle Corporation, All rights reserved. 6 Accessing a Database Using the JDBC API.
Copyright  Oracle Corporation, All rights reserved. 7 Accessing a Database Using SQLJ.
Работа с базами данных – JDBC Введение в JDBC. JDBC JDBC (Java DataBase Connectivity) – технология доступа к базам данных для Java Состоит из: API (java.sql.
Leman Akoglu 11/11/ Fall 2009 Recitation Homework 9 Building A Web Application Phase-II School of Computer Science.
Enterprise Java v040918JBoss DataSource Setup1 Setting up DataSources in JBoss References: JBoss Wiki –
Creating competitive advantage Copyright © 2003 Enterprise Java Beans Presenter: Wickramanayake HMKSK Version:0.1 Last Updated:
Java Naming and Directory Interface Matt. 2 What is JNDI.
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.
Enterprise Java Transactions Source: “Enterprise JavaBeans, 3rd Edition”, Richard Monson-Haefel.
EXAMPLE I An application showing JDBC access to Cloudscape.
16 Java Database Connectivity. 2 Understand the JDBC Understand the steps of the JDBC: 1.) Importing packages 2.) Opening a connection to a database 3.)
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.
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.
Session Beans Based on: Patel, Brose, Silverman, Mastering Enterprise JavaBeans 3.0.
D Copyright © 2004, Oracle. All rights reserved. BMP Entity EJBs J2EE Connector Architecture.
Web Programming Assistant Professor Xiaozhong Liu
Using Oracle JDBC How to Run JDBC on Your Account Communication Mechanism Using Metadata Building a Database Auto Commit v.s Atomic Transaction.
JSP/Database Connectivity Instructor: Dr. M. Anwar Hossain.
© D. Wong Persistent, Stored Modules (PSM) (Ref. 8.2 )  A way to create and store procedures or functions with a database schema  The procedure/functions.
Instructor: Jinze Liu Fall /8/2016Jinze University of Kentucky 2 Database Project Database Architecture Database programming.
JDBC and OCCI 10/29/2017.
Java Access to RDB Relational databases (RDBs) dominate today, due to:
JDBC 15-Apr-18.
Java web hosting at CERN
JDBC 21-Aug-18.
JDBC(Java Database Connectivity
JDBC 15-Nov-18.
Objectives In this lesson, you will learn to:
Using a Database with JDBC
JDBC API.
JDBC Example.
Presentation transcript:

1 JDBC Resource Registration on WebSphere Console javax.naming.InitialContext ctx = new javax.naming.InitialContext(); javax.sql.DataSource ds = (javax.sql.DataSource)ctx.lookup("jdbc/DB2UDB"); java.sql.Connection conn = ds.getConnection(); NO !!! Default: TRANSACTION_NONE Sharable Connection Information logging every called Servlet/JSP 코드에서 명시적으로 conn.close() 하였더라도 Servlet/JSP 가 끝날 때까지 connection 은 pool 로 release 되지 않음  불필요한 과도한 JDBC 연결자원사용됨 / 경우에 따라 성능장애

2 J2EE: DataSource Resource Reference when EAR packaging jdbc/DB2UDB User Application Database B WebSphere Application Server Transaction manager jdbc/MyDB Resource Manager EAR Resource Reference Mapping during deploy javax.naming.InitialContext ctx = new javax.naming.InitialContext(); javax.sql.DataSource ds = (javax.sql.DataSource)ctx.lookup(“java:comp/env/jdbc/MyDB"); java.sql.Connection conn = ds.getConnection(); register end request start to end with a thread lifetime Global JNDI name Local JNDI name

3 Using AAT, Datasource Resource Reference javax.naming.InitialContext ctx = new javax.naming.InitialContext(); javax.sql.DataSource ds = (javax.sql.DataSource)ctx.lookup("java:comp/env/jdbc/UnsharedDS"); java.sql.Connection conn = ds.getConnection(); 공유범위 : Shareable/Unshareable AAT  EAR 웹모듈  자원참조 유형 : DataSource

4 Using AAT, Transaction Isolation Level 동시성 제어 (Concurrency Control) 이슈 Transaction Isolation Level (1) TRANSACTION_NONE (default) (2) TRANSACTION_READ_UNCOMMITTED (3) TRANSACTION_READ_COMMITTED (4) TRANSACTION_REPEATABLE_READ (5) TRANSACTION_SERIALIZABLE 902 웹스피어 5.0 데이타베이스 연결 설정법

5 public void method() throws Exception { String name = getEmployeeName("7904"); String dept = getDeptName("1234"); } public String getEmployeeName(String id) throws Exception { Connection conn = null; Statement stmt = null; String name = null; try{ javax.sql.DataSource ds = (javax.sql.DataSource)ctx.lookup("java:comp/env/jdbc/A"); conn = ds.getConnection(); stmt = conn.createStatement(); Result rs = stmt.executeQuery("select ename from emp where empno = " + id); name = rs.getString("ename"); rs.close(); } finally{ if(stmt != null) try{stmt.close();}catch(Exception e){} if(conn != null) try{conn.close();}catch(Exception e){} } return name; } public String getDeptName(String id) throws Exception { Connection conn = null; Statement stmt = null; String name = null; try{ javax.sql.DataSource ds = (javax.sql.DataSource)ctx.lookup("java:comp/env/jdbc/A "); conn = ds.getConnection(); stmt = conn.createStatement(); Result rs = stmt.executeQuery("select deptname from dept where deptno = " + id); name = rs.getString("deptname"); rs.close(); } finally{ if(stmt != null) try{stmt.close();}catch(Exception e){} if(conn != null) try{conn.close();}catch(Exception e){} } return name; } Database B Resource Manager JDBC connection pool request end within a thread boundary Shareable Connection allocate release

6 public void method() throws Exception { String name = getEmployeeName("7904"); String dept = getDeptName("1234"); } public String getEmployeeName(String id) throws Exception { Connection conn = null; Statement stmt = null; String name = null; try{ javax.sql.DataSource ds = (javax.sql.DataSource)ctx.lookup("java:comp/env/jdbc/A"); conn = ds.getConnection(); stmt = conn.createStatement(); Result rs = stmt.executeQuery("select ename from emp where empno = " + id); name = rs.getString("ename"); rs.close(); } finally{ if(stmt != null) try{stmt.close();}catch(Exception e){} if(conn != null) try{conn.close();}catch(Exception e){} } return name; } public String getDeptName(String id) throws Exception { Connection conn = null; Statement stmt = null; String name = null; try{ javax.sql.DataSource ds = (javax.sql.DataSource)ctx.lookup("java:comp/env/jdbc/A "); conn = ds.getConnection(); stmt = conn.createStatement(); Result rs = stmt.executeQuery("select deptname from dept where deptno = " + id); name = rs.getString("deptname"); rs.close(); } finally{ if(stmt != null) try{stmt.close();}catch(Exception e){} if(conn != null) try{conn.close();}catch(Exception e){} } return name; } Database B Resource Manager JDBC connection pool Unshareable Connection allocate release allocate

7 XA and non-XA JDBC Driver Provider Non-XA JDBC Driver Provider javax.naming.InitialContext ctx = new javax.naming.InitialContext(); javax.sql.DataSource ds = (javax.sql.DataSource)ctx.lookup(“java:comp/env/jdbc/MyDB"); java.sql.Connection conn = ds.getConnection(); boolean mode = conn.getAutoCommit();  true XA JDBC Driver Provider javax.naming.InitialContext ctx = new javax.naming.InitialContext(); javax.sql.DataSource ds = (javax.sql.DataSource)ctx.lookup(" java:comp/env/jdbc/MyDB "); java.sql.Connection conn = ds.getConnection(); boolean mode = conn.getAutoCommit();  false Non-XA JDBC Driver Provider : 1-phase commit resource XA JDBC Driver Provider : 2-phase commit resource

8 Non-XA JDBC Resource EJB Servlet/JSP call() Database A WebSphere Application Server ctx.lookup("java:comp/env/jdbc/A"); Question : If - Unshareable Connection - Non-XA JDBC Provider Shareable needed Global Transaction error with 1pc resource !!

9 XA JDBC Provider : 2 phase-commit XA Resource manager XA Resource manager Transaction manager User Application tx.begin() tx.commit() Database A Database B 1 phase: prepare 2 phase: commit/rollback 1 phase: in-doubt 2 phase: commit/rollback tranlog WebSphere Application Server

10 XA JDBC Provider : 2 phase-commit XA Resource manager XA Resource manager EJB1 Database A Database B EJB2 Transaction propagation

11 java.sql.Connection conn1 = null; java.sql.Statement stmt1 = null; java.sql.Connection conn2 = null; java.sql.Statement stmt2 = null; javax.transaction.UserTransaction tx = null; try { javax.naming.InitialContext ctx = new javax.naming.InitialContext(); tx = (javax.transaction.UserTransaction) ctx.lookup("java:comp/UserTransaction"); tx.begin(); // javax.sql.DataSource ds1 = (javax.sql.DataSource)ctx.lookup("java:comp/env/jdbc/A"); conn1 = ds1.getConnection(); stmt1 = conn1.createStatement(); stmt1.executeUpdate("update emp set ename = 'LWY" + count + "' where empno = 7934"); // javax.sql.DataSource ds2 = (javax.sql.DataSource)ctx.lookup("java:comp/env/jdbc/B"); conn2 = ds2.getConnection(); stmt2 = conn2.createStatement(); stmt2.executeUpdate("update emp set ename = 'LWY" + count + "' where empno = 7934"); // tx.commit(); } catch(Exception e){ if ( tx != null ) try{tx.rollback();}catch(Exception ee){} } finally { if ( stmt1 != null ) try { stmt1.close();}catch(Exception e){} if ( conn1 != null ) try { conn1.close();}catch(Exception e){} if ( stmt2 != null ) try { stmt2.close();}catch(Exception e){} if ( conn2 != null ) try { conn2.close();}catch(Exception e){} } 2 phase commit sample (XA JDBC Datasource) Question : How about in EJB? CMT/BMT Database A Database B