CSE 190: Internet E-Commerce Lecture 13: Database code.

Slides:



Advertisements
Similar presentations
Connecting to Databases. connecting to DB DB server typically a standalone application Server runs on localhost for smaller sites –i.e. Same machine as.
Advertisements

Connecting to Databases. relational databases tables and relations accessed using SQL database -specific functionality –transaction processing commit.
Java Database Connectivity (JDBC). 2/24 JDBC (Java DataBase Connectivity) - provides access to relational database systems JDBC is a vendor independent.
CIS 375—Web App Dev II ADO I. 2 Introduction ADO (________ Data Objects) is a Microsoft technology for accessing data in a database. ADO is automatically.
Java, Access, SQL, HTML. Three-tier architecture involves: Client - Browser Server - Tomcat Database - Access - Server-side language - JSP could just.
Distributed Application Development B. Ramamurthy.
ActiveX Data Object ISYS 562. ADO An ActiveX control ActiveX is build upon COM, a contract that defines a standard interface by which objects communicate.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 32 Java Database.
1 C. Shahabi Application Programming for Relational Databases Cyrus Shahabi Computer Science Department University of Southern California
1 Lecture 29 More on JDBC Overview  Objectives of this lecture  JDBC and its Drivers  Connecting to Databases (Java’s Connection class)  Querying a.
CSE470 Software Engineering Fall Database Access through Java.
Adv. CoE Lab: JDBC 1 Advanced Computer Engineering Lab Objective – –to give some background on JDBC to help with the lab exercises , Semester.
Java database Programming JDBC Trademarked name of a Java API that supports Java programs that access relational databases Stand for Java DataBase Connectivity.
1 Foundations of Software Design Lecture 27: Java Database Programming Marti Hearst Fall 2002.
Three-Tier Architecture Oracle DB Server Apache Tomcat App Server Microsoft Internet Explorer HTML Tuples HTTP Requests JDBC Requests Java Server Pages.
ODBC and JDBC What are they – libraries of function calls that support SQL statements Why do we need them –Provide a way for an application to communicate.
Advanced OOP MCS-3 OOP BSCS-3 Lecture # 11. DATABASE CONNECTIVITY IN JAVA JDBC Programming JDBC (Java Database Connectivity) is the specification of a.
Lab: JDBC 1 Computer Engineering Lab III v Objective –to give some background on JDBC to help with the lab exercises , Semester 1,
Introduction to JDBC (Java Database Connectivity).
CIS 270—App Dev II Big Java Chapter 22 Relational Databases.
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
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.
Helena Pomezná, ciz034 St. skupina: L392 FEI, VŠB-TUO Ak. rok. 2002/2003 Download:
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.
© Wang Bin 2004 JDBC ----Java Database Connectivity.
CSE470 Software Engineering Fall Database Access through Java.
Beginning Databases with JDBC Mike Bradley Adapted from and notes by Kevin Parker, Ph.D.
Intro to JDBC To effectively use Java Data Base Connectivity we must understand: 1.Relational Database Management Systems (RDBMS) 2.JDBC Drivers 3.SQL.
Database 20/2/12 Connection. 
Database Programming in Java Corresponds with Chapter 32, 33.
CIS 270—Application Development II Chapter 25—Accessing Databases with JDBC.
DBI tutorial February 5 th, What is DBI DBI is short for Database Interface, which is a Perl module DBI is short for Database Interface, which is.
Georgia Institute of Technology Making Text for the Web part 5 Barb Ericson Georgia Institute of Technology March 2006.
MySQL, Java, and JDBC CSE 3330 Southern Methodist University.
Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 1 Database & Server-side Scripting Tutorial 10.
JDBC Tutorial MIE456 - Information Systems Infrastructure II Vinod Muthusamy November 4, 2004.
JDBC (Java Database Connectivity) SNU OOPSLA Lab. October 2005.
Designing and Developing WS B. Ramamurthy. Plans We will examine the resources available for development of JAX-WS based web services. We need an IDE,
Servlets Database Access. Agenda:  Setup Java Environment  Install Database  Install Database Drivers  Create Table and add records  Accessing a.
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.
How to Connect to Database ODBC (Open Database Connectivity) ADO (ActiveX Data Object) ASP Code To Connect to Database Recordset Object Navigating through.
Accessing Database using JDBC. JDBC Objectives Gain basic knowledge of Java JDBC Become familiar with the basics of interacting with a database using.
COMP201 Java Programming Topic 15: Database Connectivity JDBC Reading: Chapter 4, Volume 2.
Chapter 25 Databases. Chapter Scope Database concepts Tables and queries SQL statements Managing data in a database Java Foundations, 3rd Edition, Lewis/DePasquale/Chase25.
JDBC Establish a connection with a database or access any tabular data source Send SQL statements Process the results Two major sets of interfaces: JDBC.
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.
Java and Databases. JDBC Architecture Java Application JDBC API Data Base Drivers AccessSQL Server DB2InformixMySQLSybase.
COMP 321 Week 4. Overview Normalization Entity-Relationship Diagrams SQL JDBC/JDBC Drivers hsqldb Lab 4-1 Introduction.
EXAMPLE I An application showing JDBC access to Cloudscape.
Lab 8 Data Access Using Microsoft ActiveX Data Object (ADO)
Database Connectivity What is ADO. What is ADO? ADO is a Microsoft technology ADO stands for ActiveX Data Objects ADO is a Microsoft Active-X component.
Basics of JDBC.
DBI: The Neophyte's Guide1 What is DBI? DBI = DataBase Interface DBI is database-independent DBI allows you to write code that interacts with databases.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 6: Accessing a database with PHP Rob Gleasure robgleasure.com.
Web Programming Assistant Professor Xiaozhong Liu
Umair Javed©2005 Enterprise Application Development Java Database Connectivity (JDBC) JDBC1.
JDBC Java and Databases. SWC – JDBC JDBC – Java DataBase Connectivity An API (i.e. a set of classes and methods), for working with databases in.
SQL pepper. Why SQL File I/O is a great deal of code Optimal file organization and indexing is critical and a great deal of code and theory implementation.
JSP/Database Connectivity Instructor: Dr. M. Anwar Hossain.
JDBC. What is JDBC JDBC is an acronym for –Java Data Base Connectivity. It allows java program to connect to any database.
Java Access to RDB Relational databases (RDBs) dominate today, due to:
Lec - 14.
HW#4 Making Simple BBS Using JDBC
Perl Database – Just Enough
JDBC Example.
ASP Database Operations
Presentation transcript:

CSE 190: Internet E-Commerce Lecture 13: Database code

ASP Database code (ADO) ADO: Microsoft standard for connecting to databases ADO = Active Data Objects API is always accessible from within ASP ADO also used from within application tier components (i.e. VB, C++ components)

ADO Accessing a DB with ADO 1.Create ADO connection 2.Open the DB connection 3.Create an ADO Recordset 4.Open the Recordset 5.Extract the fields from the recordset 6.Close the recordset 7.Close the connection

ADO: Connections DSN: Analogous to a URL for a database DSN = Data Source Name

ADO: Connecting without DSN <% set connection = Server.CreateObject( “ADODB.Connection” ) connection.Provider = “Microsoft.Jet.OLEDB.4.0” Connection.Open “c:/demos/northwind.mdb” %>

ADO: Connecting with DSN <% set connection = Server.CreateObject( “ADODB.Connection” ) connection.Open “Northwind” %>

ADO: Creating a DSN In Windows 2000, Settings -> Control Panel -> Administrative Tools - > ODBC Choose “System DSN”, and then “Add…” Enter any identifying string for the DSN Choose “Select…” to specify where to find the source DB file

ADO: Connection Object Properties: Methods: CommandTimeoutSeconds to wait for command to finish ConnectionStringString used to create connection (e.g. northwind) StateWhether connection is open or closed ExecuteExecute SQL query, command, or statement OpenOpens a connection CancelCancels a currently executing command CloseCloses the connection BeginTransBegins a transaction RollbackTransCancel changes in current transaction CommitTransCommits a transaction

ADO: Creating Recordset Recordset: A table of rows representing the results of a query or contents of an existing table Recordset via SQL query: <% set connection = Server.CreateObject( “ADODB.Connection” ) connection.Open “northwind” set rs = Server.CreateObject( “ADODB.Recordset” ) rs.Open( “Select * from Customers” ), connection %>

ADO Recordset: Accessing Data <% set connection = Server.CreateObject( "ADODB.Connection“ ) connection.Open “northwind” set rs=Server.CreateObject( "ADODB.recordset“ ) rs.Open "Select * from Customers", connection for each x in rs.fields response.write( x.name ) response.write( " = “ ) response.write( x.value ) next %>

ADO: Accessing Data from all rows <% set connection = Server.CreateObject( "ADODB.Connection“ ) connection.Open “northwind” set rs=Server.CreateObject( "ADODB.recordset“ ) rs.Open "Select * from Customers", connection do until rs.EOF for each x in rs.fields response.write( x.name ) response.write( " = “ ) response.write( x.value ) next response.write “ ” rs.MoveNext loop %>

ADO: Clean up <% set connection = Server.CreateObject( "ADODB.Connection“ ) connection.Open “northwind” set rs=Server.CreateObject( "ADODB.recordset“ ) rs.Open "Select * from Customers", connection do until rs.EOF for each x in rs.fields response.write( x.name ) response.write( " = “ ) response.write( x.value ) next response.write “ ” rs.MoveNext loop rs.close connection.close %>

JDBC JDBC: Java version of ODBC, providing same functionality as ADO ODBC: pre-ADO DB connect technology from Microsoft Using JDBC: 1.Load the JDBC-ODBC bridge 2.Connect to data source 3.Execute SQL command 4.Access Recordset 5.Clean up

JDBC: Loading ODBC bridge Must load Java driver to connect to database Two methods: 1.Specify driver class name in code: Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver“ ); 2.Specify driver via Java property: jdbc.drivers = sun.jdbc.odbc.JdbcOdbcDriver

JDBC: Connecting to DB import java.sql.*; public class MyTest { public static void main( String[] args ) { String DSN = “jdbc:odbc:somedsn”; Connection conn = null; conn = DriverManager.getConnection( DSN, “sa”, “” ); }

JDBC: Executing SQL import java.sql.*; public class MyTest { public static void main( String[] args ) { String DSN = “jdbc:odbc:somedsn”; Connection conn = null; Statement statement = null; conn = DriverManager.getConnection( DSN, “sa”, “” ); statement = conn.createStatement(); ResultSet result = statement.executeQuery( “SELECT programmer, cups FROM JoltData ORDER BY cups DESC;"); }

JDBC: Access Recordset import java.sql.*; public class MyTest { public static void main( String[] args ) { String DSN = “jdbc:odbc:somedsn”; Connection conn = null; Statement statement = null; conn = DriverManager.getConnection( DSN, “sa”, “” ); statement = conn.createStatement(); ResultSet result = statement.executeQuery( “SELECT programmer, cups FROM JoltData ORDER BY cups DESC;"); // for each row of data (note typed fields) while( result.next() ) { String name = result.getString( “programmer” ); int cups = result.getInt( “cups” ); }

JDBC: Clean up import java.sql.*; public class MyTest { public static void main( String[] args ) { String DSN = “jdbc:odbc:somedsn”; Connection conn = null; Statement statement = null; conn = DriverManager.getConnection( DSN, “sa”, “” ); statement = conn.createStatement(); ResultSet result = statement.executeQuery( “SELECT programmer, cups FROM JoltData ORDER BY cups DESC;"); // for each row of data (note typed fields) while( result.next() ) { String name = result.getString( “programmer” ); int cups = result.getInt( “cups” ); } // Clean up conn.close(); }

Perl DBI: Quick Overview use DBI; # Connect to DB my $dbh = DBI->connect( 'DBI:Oracle:payroll‘ ) or die "Couldn't connect to database: ". DBI->errstr; # Prepare SQL for execution my $sth = $dbh->prepare( 'SELECT * FROM people WHERE lastname = ?') or die "Couldn't prepare statement: ". $dbh->errstr; print "Enter name> "; while ($lastname = <>) { # Read input from the user chomp $lastname; $sth->execute( $lastname ) # Execute the query or die "Couldn't execute statement: ". $sth->errstr; # Fetch the record set while = $sth->fetchrow_array()) { my $firstname = $data[1]; my $id = $data[2]; print "\t$id: $firstname $lastname\n"; } if ($sth->rows == 0) { print "No names matched `$lastname'.\n\n"; } # Clean up statement $sth->finish; print "\n"; print "Enter name> "; } # Clean up connection $dbh->disconnect;

References ASP – JDBC – eTraining/Database/JDBCShortCourse/jdbc/jd bc.html Perl –