Prof: Dr. Shu-Ching Chen TA: Sheng Guan

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 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.
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
Object Oriented Programming Java Java’s JDBC Allows access to any ANSI SQL-2 DBMS Does its work in terms of SQL The JDBC has classes that represent:
1 Lecture 05: Database Programming (JDBC). 2 Outline JDBC overview JDBC API Reading: Chapter 10.5 Pointbase Developer Manual.
JDBC Overview Autumn 2001 Lecturer: C. DeJong. Relational Databases widespread use used via SQL (Structured Query Language) freely available powerful.
1 Sub-queries and Views. 2 A Complex Query We would like to create a table containing 3 columns: –Sailor id –Sailor age –Age of the oldest Sailor How.
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.
Three-Tier Architecture Oracle DB Server Apache Tomcat App Server Microsoft Internet Explorer HTML Tuples HTTP Requests JDBC Requests Java Server Pages.
UFCE4Y UFCE4Y-20-3 Components and Services Julia Dawson.
JAVA JDBC JAVA JDBC Java Database Programming Lamiaa Said.
Java MS Access database connectivity Follow these steps: 1)Go to the start->Control Panel->Administrative Tools- > data sources. 2)Click Add button and.
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
Helena Pomezná, ciz034 St. skupina: L392 FEI, VŠB-TUO Ak. rok. 2002/2003 Download:
Database Management Systems 1 Oracle Programming.
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.
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.
CS 405G: Introduction to Database Systems Database programming.
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.
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.
Stored procedures1 Stored procedures and functions Procedures and functions stored in the database.
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.
Chapter 8 Databases.
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.
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.
JDBC CS 124. JDBC Java Database Connectivity Database Access Interface provides access to a relational database (by allowing SQL statements to be sent.
12/6/2015B.Ramamurthy1 Java Database Connectivity B.Ramamurthy.
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.
EXAMPLE I An application showing JDBC access to Cloudscape.
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.
Database Management Systems 1 Raghu Ramakrishnan Database Application Development Chpt 6 Xin Zhang.
JDBC Java DataBase Connectivity. Loading the driver import java.sql.*... Class.forName("org.postgresql.Driver")‏
JAVA DATABASE OOP Praktek dengan Java Miswar,S.st Sumber : Eddy Muntina Dharma,ST,MT.
Advanced Java Session 5 New York University School of Continuing and Professional Studies.
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.
Using Oracle JDBC How to Run JDBC on Your Account Communication Mechanism Using Metadata Building a Database Auto Commit v.s Atomic Transaction.
JDBC. What is JDBC JDBC is an acronym for –Java Data Base Connectivity. It allows java program to connect to any database.
CS320 Web and Internet Programming Database Access with JDBC Chengyu Sun California State University, Los Angeles.
Instructor: Jinze Liu Fall /8/2016Jinze University of Kentucky 2 Database Project Database Architecture Database programming.
JDBC – Java DataBase Connectivity
Interacting with Database
Lec - 14.
JDBC 15-Apr-18.
JDBC – Java Database Connectivity
CS320 Web and Internet Programming Database Access with JDBC
JDBC 21-Aug-18.
HW#4 Making Simple BBS Using JDBC
JDBC – Java DataBase Connectivity
Client Access, Queries, Stored Procedures, JDBC
JDBC – Java DataBase Connectivity
JDBC 15-Nov-18.
JDBC – ODBC DRIVERS.
Java Database Connectivity
Bolat Azamat, Kim Dongmin
JDBC Example.
JDBC – Java DataBase Connectivity
Java Chapter 6 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

Prof: Dr. Shu-Ching Chen TA: Sheng Guan Embedded SQL Prof: Dr. Shu-Ching Chen TA: Sheng Guan

Problems with using interactive SQL Standard SQL is not “Turing-complete”. • E.g., Two profs are “colleagues” if they’ve co-taught a course. • We can’t write a query to find all colleagues of a given professor because we have no loops or recursion. • You can’t control the format of its output. • And most users shouldn’t be writing SQL queries! • You want to run queries that are based on user input, not have users writing actual queries. http://www3.ntu.edu.sg/home/ehchua/programming/sql/relational_database_design.html

SQL + a conventional language • If we can combine SQL with code in a conventional language, we can solve these problems. • But we have another problem: • SQL is based on relations, and conventional languages have no such type. • It is solved by • feeding tuples from SQL to the other language one at a time, and • feeding each attribute value into a particular variable. http://www3.ntu.edu.sg/home/ehchua/programming/sql/relational_database_design.html

JDBC http://www3.ntu.edu.sg/home/ehchua/programming/sql/relational_database_design.html

JDBC - Simple Example Steps: Load the driver and register it with the driver manager Connect to a database Create a statement Execute a query and retrieve the results, or make changes to the database Disconnect from the database http://www3.ntu.edu.sg/home/ehchua/programming/sql/relational_database_design.html

JDBC - Simple Example API for accessing and processing DB data import java.sql.*; public class jdbctest { public static void main(String args[]){ try{ Class.forName("org.postgresql.Driver"); Connection con = DriverManager.getConnection ("jdbc:postgresql://hugo.cs.fiu.edu:5432/testdb", "user", "pass"); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery ("select name, number from mytable where number < 2"); while( rs.next() ) System.out.println(rs.getString(1) + " (" + rs.getInt(2) + ")"); rs.close(); stmt.close() con.close(); } catch(Exception e){ System.err.println(e); } } } Java launcher looks for “main” method http://www3.ntu.edu.sg/home/ehchua/programming/sql/relational_database_design.html “catch” an Exception here (could be an SQLException)

JDBC Example.java: Import SQL Package, Prepare DB Objects Drafting out the sample input forms, queries and reports, often helps.

JDBC Example.java: Load the driver! Drafting out the sample input forms, queries and reports, often helps.

JDBC Example.java: Make the connection to the DB.. Drafting out the sample input forms, queries and reports, often helps.

JDBCExample.java: Create + Execute a Statement! Drafting out the sample input forms, queries and reports, often helps.

What do I need to run this code ? Download the driver http://jdbc.postgresql.org/download.html Compile the code javac JDBCExample.java Drafting out the sample input forms, queries and reports, often helps.

JDBCExample.java: Import SQL Package, Prepare DB Objects Drafting out the sample input forms, queries and reports, often helps.

JDBCExample.java: Load the driver! Drafting out the sample input forms, queries and reports, often helps.

JDBCExample.java: Make the connection to the DB.. Drafting out the sample input forms, queries and reports, often helps.

JDBCExample.java: Create + Execute a Statement! Drafting out the sample input forms, queries and reports, often helps.

JDBCExample.java: INSERTs, UPDATEs.. Drafting out the sample input forms, queries and reports, often helps.

JDBCExample.java: Use Prepared Statement for Insertion! http://www3.ntu.edu.sg/home/ehchua/programming/sql/relational_database_design.html

JDBCExample.java: Use Prepared Statement for Insertion! Result of using Prepared Statement for Insertion : http://www3.ntu.edu.sg/home/ehchua/programming/sql/relational_database_design.html

What is “preparation” ? Preparing a statement includes parsing the SQL, compiling and optimizing it. The resulting PreparedStatement can be executed any number of times without having to repeat these steps. http://www3.ntu.edu.sg/home/ehchua/programming/sql/relational_database_design.html

If the query isn’t known until run time • You can hard-code in the parts you know, and use “?” as a placeholder for the values you don’t know. • This is enough to allow a PreparedStatement to be constructed. • Once you know values for the placeholders, methods setString, setInt, etc. let you fill in those values. Drafting out the sample input forms, queries and reports, often helps.

JDBCExample.java: Get and Process a Result Set.. Drafting out the sample input forms, queries and reports, often helps.

JDBCExample.java: DROP a table and close connection.. Drafting out the sample input forms, queries and reports, often helps.

Reference http://www.cdf.toronto.edu/~csc343h/winter/slide s/embedded/Embedded.pdf https://www.coursehero.com/file/8803580/Embed dedSQL/ Drafting out the sample input forms, queries and reports, often helps.