JDBC - JDBC Java DataBase Connectivity CSE432 Object...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
JDBC – Java DataBase Connectivity CSE432 Object Oriented Software Engineering
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 What is JDBC? “An API that lets you access virtually any tabular data source from the Java programming language” JDBC Data Access API – JDBC Technology Homepage What’s an API? See J2SE documentation What’s a tabular data source? “… access virtually any data source, from relational databases to spreadsheets and flat files .” JDBC Documentation We’ll focus on accessing Oracle databases
Background image of page 2
3 General Architecture What design pattern is implied in this architecture? What does it buy for us? Why is this architecture also multi-tiered?
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4
Background image of page 4
5 Basic steps to use a database in Java 1.Establish a connection 2.Create JDBC Statements 3.Execute SQL Statements 4.GET ResultSet 5. Close connections
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 1. Establish a connection import java.sql.*; Load the vendor specific driver Class.forName("oracle.jdbc.driver.OracleDriver"); What do you think this statement does, and how? Dynamically loads a driver class, for Oracle database Make the connection Connection con = DriverManager.getConnection( "jdbc:oracle:thin:@oracl e-prod:1521:OPROD", username, passwd); What do you think this statement does? Establishes connection to database by obtaining a Connection object
Background image of page 6
7 2. Create JDBC statement(s) Statement stmt = con.createStatement() ; Creates a Statement object for sending SQL statements to the database
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8 Executing SQL Statements String createLehigh =  " Create table Lehigh  " +   " (SSN Integer not null, Name VARCHAR(32),  " + " Marks Integer) " ; stmt. executeUpdate (createLehigh); //What does this statement do? String insertLehigh =  " Insert into Lehigh values + " (123456789,abc,100) " ; stmt. executeUpdate (insertLehigh);
Background image of page 8
Get ResultSet String queryLehigh =  " select * from Lehigh " ; ResultSet  rs = Stmt. executeQuery (queryLehigh); //What does this statement do? while (rs.next()) {
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 25

JDBC - JDBC Java DataBase Connectivity CSE432 Object...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online