Using Java with PSQL and Oracle Thanks to Drs. Raj and Liu for sharing some of these slides TRUDY: ALSO NEED SAMPLE PROGRAM.

Slides:



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

CE203 - Application Programming Autumn 2013CE203 Part 51 Part 5.
Java II--Copyright © Tom Hunter. Chapter 18 JDBC.
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.
JDBC - Java Database Connectivity The objectives of this chapter are: To describe the architecture of JDBC To outline the classes in the java.sql package.
Distributed Application Development B. Ramamurthy.
JDBC CS-328. JDBC Java API for accessing RDBMS Allows use of SQL for RDBMS programming Can be used for: –embedded SQL –execution of stored queries.
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 JDBC Java Database Connectivity. 2 c.pdf
Java Database Connectivity JDBC ICW Lecture 12 Errol Thompson.
JDBC Overview Autumn 2001 Lecturer: C. DeJong. Relational Databases widespread use used via SQL (Structured Query Language) freely available powerful.
CS34311 CS3431 – Database Systems I Project Overview Murali Mani.
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 Lecture 29 More on JDBC Overview  Objectives of this lecture  JDBC and its Drivers  Connecting to Databases (Java’s Connection class)  Querying a.
1 Foundations of Software Design Lecture 27: Java Database Programming Marti Hearst Fall 2002.
Murali Mani Web Interface. Murali Mani Options PHP with mySQL JSP/Servlets with JDBC on mySQL/Oracle Others …
JDBC Java API for Database Connectivity. Layout of this recitation Introduction to JDBC API JDBC Architecture Understanding the design of JDBC API –Classes.
1 CSC 440 Database Management Systems JDBC This presentation uses slides and lecture notes available from
Overview of JDBC and Pro*C 1 Overview of JDBC,Pro*C and Oracle connectivity on Omega CSE 5330 – Database Systems.
Database Management Systems 1 Oracle Programming.
CS178 Database Management “JDBC”. What is JDBC ? JDBC stands for “Java DataBase Connectivity” The standard interface for communication between a Java.
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.
Java Utility Classes CS 21b. Some Java Utility Classes Vector Hashtable StringTokenizer * import java.util.*;
Views, Indexes and JDBC/JSP tutorial Professor: Dr. Shu-Ching Chen TA: Haiman Tian 1.
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.
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.
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.
Introduction to JDBC Michelle Lee, Ye Wu & Jeff Offutt SWE 432 Design and Implementation of Software for the Web.
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.
1 JDBC Aum Amriteshwaryai Namah. 2 2 JDBC – Java DataBase Connectivity.
Index and JDBC/JSP tutorial Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
JDBC Enterprise Systems Programming. JDBC  Java Database Connectivity  Database Access Interface provides access to a relational database (by allowing.
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.
Java Database Connectivity (JDBC). Topics 1. The Vendor Variation Problem 2. SQL and Versions of JDBC 3. Creating an ODBC Data Source 4. Simple Database.
Computer Science [3] Java Programming II - Laboratory Course Lab 9: Accessing Databases with JDBC Instructions on Setting Accesses Connecting to and Querying.
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.
COMP 321 Week 4. Overview Normalization Entity-Relationship Diagrams SQL JDBC/JDBC Drivers hsqldb Lab 4-1 Introduction.
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:
Database Access Using JDBC BCIS 3680 Enterprise Programming.
JDBC™ Fundamentals (a.k.a. Java Database Connectivity, although technically not an acronym) ©SoftMoore ConsultingSlide 1.
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)
1 Principles of Database Systems With Internet and Java Applications Today’s Topic Chapter 8: Applications Programming for Relational Databases Instructor’s.
Introduction to JDBC Instructor: Mohamed Eltabakh 1.
1 JDBC – Java Database Connectivity CS , Spring 2010.
Intro to JDBC Joseph Sant Applied Computing and Engineering Sciences Sheridan ITAL.
CS422 Principles of Database Systems JDBC and Embedded SQL Chengyu Sun California State University, Los Angeles.
JDBC Statements The JDBC Statement, CallableStatement, and PreparedStatement interfaces define the methods and properties that enables to send SQL or PL/SQL.
JDBC 15-Apr-18.
JDBC – Java Database Connectivity
JDBC 21-Aug-18.
HW#4 Making Simple BBS Using JDBC
Prof: Dr. Shu-Ching Chen TA: Sheng Guan
Design and Implementation of Software for the Web
JDBC 15-Nov-18.
Interacting with Database
MSIS 655 Advanced Business Applications Programming
JAVA DATABaSE CONNECTIVITY
JDBC Example.
Presentation transcript:

Using Java with PSQL and Oracle Thanks to Drs. Raj and Liu for sharing some of these slides TRUDY: ALSO NEED SAMPLE PROGRAM

In this slide deck: Tips for using PSQL and Oracle Some “gotchas” for working with the Java database interface

psql You will need a separate psql account – see your instructor Server runs on reddwarf You need to provide your password each time you invoke psql

psql Full documentation and a tutorial are available online Default is a command line interface that isn’t very forgiving with typos or to reissue commands Several UI skins exist; some are open source – check around or write your own

psql passwords The psql interpreter will bypass the password prompt if it sees a.pgpass file in your home directory Enter a single line: localhost:*:*:Your_Username:Your_Password (host:port:db:username:password) IMPORTANT – SEE NEXT SLIDE

psql passwords Be sure to chmod 600 to set permissions on the file Our system admin has approved storing this plain-text password IF you do not use the same password as your CS account DO NOT USE THE SAME PASSWORD AS YOUR CS ACCOUNT!

Getting started with psql Assuming you use bash: Edit your.bashrc file to include the following: export path=/usr/lib/postgresql/9.1/bin/:$path You will also need this for the Java JDBC: export CLASSPATH=/home/student/abc1234/db/ postgresql jdbc4.jar:$CLASSPATH (all one line. Substitute “/home/student/abc1234” with your own path name

Integrating psql with Java You also need the.jar file in your working directory. See my website download page for the link. Review demo program Note that much of your understanding will be achieved through experimentation and studying the appropriate javadocs!

Continue to the next slides if using Oracle

Setting Java Environment for Oracle To use sqlplus and JDBC from a Java program – Ensure CLASSPATH is set up correctly – csh users can source the following file /usr/local/bin/coraenv Put it in your.cshrc file – bash users can source the following file /usr/local/bin/oraenv Put it in your.bashrc file Sample Java program – See course webpage under DBMS Docs You must modularize this program! Understand password privacy issues involved here!

Using the CS Department Connecting to Oracle directly – sqlplus – Use this primarily for running DDL scripts Connecting to a DBMS with a Java program – Use the Oracle JDBC driver – Read CRUD and the javadocs Demonstration

Java Classes/Interfaces: java.sql, javax.sql DriverManager – getConnection Connection – createStatement, prepareStatement, commit, setAutoCommit, close Statement – executeQuery, executeUpdate, close PreparedStatement – execute, commit, close, setint, setString ResultSet – next, getString, getInt Some useful classes and methods Some useful classes and methods

JDBC Introduction Useful to read the following SUN’s JDBC tutorial – java.sun.com/docs/books/tutorial/index.html Steps for Oracle (similar for any other DBMS) – Load the driver – Connect to the DBMS – Send SQL to the DBMS – Process the results of your queries – Cleanup

Load the Driver and Connect to Oracle Several steps rolled into one Class.forName( "oracle.jdbc.driver.OracleDriver"); String url = Connection con = DriverManager.getConnection( url, dbUser, dbPassword );

Send SQL to the DBMS Just send the SQL … stmt.executeUpdate("insert into A values(2009)" ); Expect some goodies back String query = "select name, salary, emp_no from employee"; ResultSet rs = stmt.executeQuery( query );

Process Query Results Get the result set ResultSet rs = stmt.executeQuery( query ); Process the result set, row by row while ( rs.next() ) { String emp_name = rs.getString( "name“ ); int emp_no = rs.getInt( "emp_no“ ); double salary = rs.getDouble( "salary“ ); System.out.println( emp_name + ", " + emp_no + “ makes $" + salary + “.“ ); }

Java and SQL: Type Mappings Data is represented in two places – In the database SQL type DB programmer responsibility – In Java program Java type Java programmer responsibility get??? calls Java method SQL Type getIntINTEGER getObject any type getLong BIG INT getFloatFLOAT getDoubleREAL getBignumDECIMAL getBooleanBIT getStringVARCHAR getStringCHAR getDateDATE getTimeTIME getTimestamp TIME STAMP

Cleanup Close out the statement and connection stmt.close( ); con.close( );