Using Oracle JDBC How to Run JDBC on Your Account Communication Mechanism Using Metadata Building a Database Auto Commit v.s Atomic Transaction.

Slides:



Advertisements
Similar presentations
16 Copyright © 2005, Oracle. All rights reserved. Using JDBC to Access the Database.
Advertisements

19 augustus 2003augustus 2003 JSP-2. BICT 2JDBC BICT 3Install MySQL Download MySQL daemon – Free – Windows version… Start Daemon – Mysqld-nt.exe Download.
1 Lecture 05: Database Programming (JDBC). 2 Outline JDBC overview JDBC API Reading: Chapter 10.5 PostgreSQL JDBC interface documentation
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.
1 CSE5200 JDBC and JDeveloper JDBC java.sql package java.sql classes.
1 JDBC Java Database Connectivity. 2 c.pdf
1 JDBC: Java Database Connectivity. 2 Introduction to JDBC JDBC is used for accessing databases from Java applications Information is transferred from.
מסדי נתונים תשס " ג 1 JDBC Java Database Connectivity קורס מסדי נתונים.
1 Lecture 05: Database Programming (JDBC). 2 Outline JDBC overview JDBC API Reading: Chapter 10.5 Pointbase Developer Manual.
Java Database Connectivity JDBC ICW Lecture 12 Errol Thompson.
EMBEDDED SQL Pepper. WHICH LANGUAGES C Visual C++ Java Many, many more What is needed from the language: –Must know how to connect to oracle db –Must.
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.
Object-Oriented Enterprise Application Development Introduction to JDBC.
Murali Mani Web Interface. Murali Mani Options PHP with mySQL JSP/Servlets with JDBC on mySQL/Oracle Others …
Three-Tier Architecture Oracle DB Server Apache Tomcat App Server Microsoft Internet Explorer HTML Tuples HTTP Requests JDBC Requests Java Server Pages.
1 JDBC "Java Database Connectivity". 2 Getting Started Guide: etstart/GettingStartedTOC.fm.html java.sql.
Basic JDBC Use Oracle JDBC Drivers must be in the CLASSPATH
Chapter 121 Adding Power to Database Access with JSP JavaServer Pages By Xue Bai.
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
CS178 Database Management “JDBC”. What is JDBC ? JDBC stands for “Java DataBase Connectivity” The standard interface for communication between a Java.
June 1, 2000 Object Oriented Programming in Java (95-707) Java Language Basics 1 Lecture 8 Object Oriented Programming in Java Advanced Topics Java Database.
JDBC. What is JDBC JDBC is an acronym for –Java Data Base Connectivity. It allows java/jsp program to connect to any database.
Database Environment Chapter 2 AIT632 Sungchul Hong.
 2004 Keith Vander Linden. All Rights Reserved. Calvin CollegeDepartment of Computer Science(1/25) Database Programming with JDBC Keith Vander Linden.
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.
1 Introducing Eclipse DTP for Ingres An Introduction GIUA Juni 2007 J. Peel Ingres Corp.
Object-Oriented Software How does it differ from procedural? How is it similar to procedural? Why has it become so popular? Does it replace or supplement.
Servlets Database Access. Agenda:  Setup Java Environment  Install Database  Install Database Drivers  Create Table and add records  Accessing a.
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.
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.
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.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
JDBC – Java Database Concentricity
Copyright  Oracle Corporation, All rights reserved. 6 Accessing a Database Using the JDBC API.
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 the UML Way versjon Only to be used in connection with the book "Java the UML Way", by Else Lervik and.
Copyright  Oracle Corporation, All rights reserved. 7 Accessing a Database Using SQLJ.
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.
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.
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
Basics of JDBC.
JDBC (Java Database Connectivity)
Introduction to JDBC Instructor: Mohamed Eltabakh 1.
1 JDBC – Java Database Connectivity CS , Spring 2010.
CS422 Principles of Database Systems JDBC and Embedded SQL Chengyu Sun California State University, Los Angeles.
JDBC. What is JDBC JDBC is an acronym for –Java Data Base Connectivity. It allows java program to connect to any database.
JDBC Java Data Base Connectivity נערך ע"י: אורי רוטנברג הנחיה: ד"ר תמר בניה קורס: סדנא ב-Java.
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 IV IS Outline  Batch processing  Transactions  Homework #2  Examples.
Java Access to RDB Relational databases (RDBs) dominate today, due to:
1st Semester, 2017 Sanghyun Park
JDBC – Java Database Connectivity
HW#4 Making Simple BBS Using JDBC
UNIT-2 Java Database Programming
Prof: Dr. Shu-Ching Chen TA: Sheng Guan
Basic Structure of SQL The basic structure of an SQL expression consists of three clauses: The select clause corresponds to the projection operation of.
Interacting with Database
JDBC Example.
CS3220 Web and Internet Programming Database Access with JDBC
CS3220 Web and Internet Programming Database Access with JDBC
Presentation transcript:

Using Oracle JDBC How to Run JDBC on Your Account Communication Mechanism Using Metadata Building a Database Auto Commit v.s Atomic Transaction

# environment variables for Oracle setenv ORACLE_TERM vt100 setenv ORACLE_SID CIS setenv ORACLE_BASE /u01/home/dba/oracle setenv ORACLE_HOME /u01/home/dba/oracle/product/7.1.4 setenv NLS_LANG AMERICAN_AMERICA.US7ASCII set path=($ORACLE_HOME/bin $path) # environment variables for Java class files setenv CLASSPATH./:/pkg/java1.1.6/lib/classes.zip: /pkg/cis550/JDBC/lib/classes111.zip # path to find the Java compiler and VM set path=(/pkg/java-1.1.6/bin. $path ) # path to find libraries for Oracle JDBC drivers setenv LD_LIBRARY_PATH /pkg/cis550/JDBC/lib setenv EPC_DISABLED TRUE

class JdbcTest { public static void main (String args []) throws SQLException, IOException { try { Class.forName ("oracle.jdbc.driver.OracleDriver"); } catch (/*ClassNotFound*/ Exception e) { e.printStackTrace (); } Connection conn = Statement stmt = conn.createStatement (); ResultSet rset = stmt.executeQuery ("select table_name from tabs"); while (rset.next ()) { System.out.println (rset.getString (1)); }; stmt.close(); conn.close();} }

Database Accessing Mechanism Registering a database driver. Using DriverManager to obtain a Connection that represents a database connection. Sending a SQL statement to the database using Statement. Retrieving the query result with a ResultSet.

Using Metadata Class.forName ("oracle.jdbc.driver.OracleDriver"); Connection conn= Statement stmt = conn.createStatement (); ResultSet rset = stmt.executeQuery(sql_query_string); ResultSetMetaData metadata = rset.getMetaData(); int numcols = metadata.getColumnCount(); // how many columns String labl1 = metadata.getColumnLabel(1); // get the first label int size = metadata.getColumnDisplaySize(1); // get the column width Look into the database itself and its contents.

Building a Database Repeatedly use INSERT INTO Increase the efficiency by providing PreparedStatement: database interprets the prepared statement and creates its template just once. insertSailor = conn.prepareStatement(“INSERT INTO Sailor VALUES(?, ?, ?); //sailor_name, sailor_rating, sailor_age

Atomic Transactions A newly-created Connection is “auto commit” Each update is as a separate transaction and automatically committed to the database. How to “group” several updates into a single “atomic” transaction? –Take Connection out of “auto commit” mode. –Explicitly call commit() to a batch of transactions –call rollback() to abort a batch of transactions.

Class.forName ("oracle.jdbc.driver.OracleDriver"); Connection conn= conn.setAutoCommit(FALSE); conn.setTransactionIsolation(Connection.TRANSACTION_READ _COMMITTED); Statement stmt = conn.createStatement (); try{ stmt.executeUpdate(sql_str_Insert_Account_Table); stmt.executeUpdate(sql_str_Create_History_Table); stmt.executeUpdate(sql_str_Insert_History_Table); conn.commit(); // commit the updates } catch(SQLException e) { conn.rollback(); // removes all updates from the database }