Murali Mani SQL-PL Interface. Murali Mani Some Possible Options Web Interface Perl /CGI with Oracle/mySQL Install your own web server and use servlets.

Slides:



Advertisements
Similar presentations
Mod_perl High speed dynamic content. Definitions Apache – OpenSource httpd server Perl – OpenSource interpreted programming language mod_perl – OpenSource.
Advertisements

Connecting to Databases. connecting to DB DB server typically a standalone application Server runs on localhost for smaller sites –i.e. Same machine as.
PHP SQL. Connection code:- mysql_connect("server", "username", "password"); Connect to the Database Server with the authorised user and password. Eg $connect.
Programming MySQL, Perl COEN 351. Reading List Paul DuBois: MySQL and Perl for the Web, New Riders, 2002 Jacqueline D. Hamilton: CGI Programming 101,
Social Web Design 1 Darby Chang Social Web Design.
Molecular Biomedical Informatics Web Programming 1.
Copyright © 2004 ProsoftTraining, All Rights Reserved. Lesson 11: Advanced Web Technologies.
Lecture 11 Server Side Interaction
ArrayExpress Query Interface Gonzalo Garc í a Lara January, / 24.
Lecture plan Information retrieval (from week 11)
NEVUG - August 2004 To Boldly Go: Using Perl and the Perl DBI as an Adjunct to MS Access for Custom Reports Maggie Rioux MBLWHOI Library Woods Hole, Mass.
1/16 Steven Leung Introduction to HTML/CGI/JavaScript Intro to HTML/CGI/JavaScript How the Web Works HTML: Basic Concept CGI: Basic Concept JavaScript:
WaveMaker Visual AJAX Studio 4.0 Training
건전지로 달리는 쟝고 세미나. 정재성 Django Web Framework CGI.
Adding Dynamic Content to your Web Site
W EB A PPLICATION D EVELOPMENT A PPLICATION T O B IO -I NFORMATICS -III Vicky Khanna M-Tech Bioinformatics.
1 Database Driven Web Application Clients Application Servers including web servers Database Server Traditional client-server (2-tier architecture): client:
Tux2 Database The Architecture of Our System © Juhani Välimäki 2005.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic Server Side Web Technologies: Part 2.
CS34311 CS3431 – Database Systems I Project Overview Elke A. Rundensteiner.
CS34311 CS3431 – Database Systems I Project Overview Murali Mani.
7/2/2015Murali Mani -- CS5421 Database Management Systems DB Application Development Project Statement + Introduction to Oracle.
M.P. Johnson, DBMS, Stern/NYU, Spring C : Database Management Systems Lecture #21 M.P. Johnson Stern School of Business, NYU Spring, 2005.
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 …
Dynamic Web site With PHP and MySQL. MySQL The combination of MySQL database and PHP scripting language is optimum for building dynamic websites. MySQL.
Julien Thibault / Phil Brewster / Kristina Doing-Harris
 2004 Prentice Hall, Inc. All rights reserved. Chapter 25 – Perl and CGI (Common Gateway Interface) Outline 25.1 Introduction 25.2 Perl 25.3 String Processing.
PHP Programming. Topics Background and History of PHP Installation Comments in PHP Variables Conditions Loops Functions File Handling Database Handling.
SJSU CS157B Dr. Lee1  2004 Jenny Mitchell Two Useful Tools You Can’t Live Without by Jenny Mitchell SJSU CS157B Section PHP and MySQL.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
1 CSC 440 Database Management Systems JDBC This presentation uses slides and lecture notes available from
Set 5: Perl and Database Connections
Apache Server The Apache Server Apache is a WWW server that implements the HTTP protocol. Apache runs as a daemon. This means that it is a resident.
1 UTGB Shell An Open-Source Browser Framework for the Integration of Biological Data Taro L. Saito, Shin Sasaki, Budrul Ahsan and.
Student Learning Environment on the World Wide Web l CGI-programming in Perl for the connection of databases over the Internet. l Web authoring using Frontpage.
Web Application Programming Carol Wolf Computer Science.
Web Server Administration Chapter 7 Installing and Testing a Programming Environment.
2001 IT Conference RenoPage: 1 PHP 101 PHP – You can DO IT! Greg Lawler Brooks Institute of Photography February IT Conference Reno.
Present :Arezoo Mollahasani. Step 1  Define your server connection Open MySQL WorkBench and click New Server Instance on the right of the window.
Connect. Communicate. Collaborate The Installation of RRD Measurement Archive (MA) Roman Łapacz, PSNC 27 th September, 2006 SEEREN2 Summer School, Heraklion.
Databases On The Web with perl Archie Warnock
JDBC Tutorial CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Web Server Administration Chapter 7 Installing and Testing a Programming Environment.
The HTTP is a standard that all Web browsers and Web servers must speak in order for the Web portion of the Internet to work.
1 More basics on DB access Elke A. Rundensteiner.
CITA 310 Section 7 Installing and Testing a Programming Environment (Textbook Chapter 7)
JSP Server Integrated with Oracle8i Project2, CMSC691X Summer02 Ching-li Peng Ying Zhang.
Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing.
SQOOP INSTALLATION GUIDE Lecturer : Prof. Kyungbaek Kim Presenter : Zubair Amjad.
Field Trip #24 Setting Up a Web Server. Apache Apache is one of the most successful open source web servers In 1995 the most popular web server was the.
CP476 Internet Computing Perl CGI and MySql 1 Relational Databases –A database is a collection of data organized to allow relatively easy access for retrievals,
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.
Databases and SQL CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Outline  XAMPP  XAMPP Install  Put php and HTML documents  Windows and Mac Version  Security.
COM621: Advanced Interactive Web Development Lecture 10 PHP and MySQL.
Presented by: K.AMARNATH Ht.no:10841f0045 Guided by: T.Suneetha.
Database Programming Basic JDBC Programming Concepts.
Please remember to thank our sponsors!
Internet/Web Databases
PERL.
Basics on DB access Elke A. Rundensteiner.
EVLA Archive The EVLA Archive is the E2E Archive
Advanced Web Automation Using Selenium
Introduction to Programming the WWW I
Perl Database – Just Enough
Content: What is JMeter? What can I do with JMeter?
Installing Tomcat.
Jungkee (Jake) Kim TMD and XML Jungkee (Jake) Kim
Presentation transcript:

Murali Mani SQL-PL Interface

Murali Mani Some Possible Options Web Interface Perl /CGI with Oracle/mySQL Install your own web server and use servlets with JDBC and Oracle/mySQL Non-Web Interface JDBC with Oracle/mySQL Also other options like embedded SQL

Murali Mani Perl Features (from Mike Ciaraldi’s slides) Created around 1987 by Larry Wall. A scripting language. Widely used. Utilities Web server programs (CGI). Quick reference to Perl

Murali Mani Perl – Hello World #!/usr/local/bin/perl use CGI::Carp qw(fatalsToBrowser warningsToBrowser); print "Content-type: text/html\n\n"; print (" Hello World Script \n"); print (" \n"); print (" Hello World !!!! \n"); print (" \n");

Murali Mani Perl – Hello World (Again !!) #!/usr/local/bin/perl use CGI::Carp qw(fatalsToBrowser warningsToBrowser); print "Content-type: text/html\n\n"; print <<ENDHTML; Hello World Script Hello World !!!! ENDHTML

Murali Mani Perl – printing out environment variables #!/usr/local/bin/perl -w use CGI::Carp qw(fatalsToBrowser warningsToBrowser); print "Content-type: text/html\n\n"; foreach $key (keys %{ENV}) { print ("$key = $ENV{$key} \n"); }

Murali Mani Perl DBI (Data Base Interface) module Module that supports functions for connecting to pretty much any DBMS software – Oracle, mySQL, Microsoft databases through ODBC etc.

Murali Mani How does Perl DBI work? (Image from OReilly)

Murali Mani Perl DBI: Main functions #!/usr/local/bin/perl use CGI::Carp qw(fatalsToBrowser warningsToBrowser); use DBI; use configOracle; print "Content-type: text/html\n\n"; print (" Test Oracle - 1 \n"); print (" \n"); if ($ENV{HTTP_ACCEPT}) { $ENV{ORACLE_HOME} = "/usr/local/oracle/product/11.1.0/db_1"; } $dbh = DBI->connect ("DBI:Oracle:host=$host;sid=$sid;port=$port", $userName, $passwd) || die "Database connection not made: $DBI::errstr";

Murali Mani Perl DBI (contd…) Note the usage of DBI->connect Also note configOracle.pm which looks like #!/usr/local/bin/perl package configOracle; use = = qw($host $sid $port $userName $passwd); $host = "oracle.wpi.edu"; $sid = "WPIDBR2"; $port = "1521"; $userName = "mmani"; $passwd = "mmani";

Murali Mani Perl DBI (contd…) $dropTable = $dbh->do ("DROP TABLE studentTemp"); if (!defined ($dropTable)) { print ("error in dropping table studentTemp $DBI::errstr \n"); } $crTable = $dbh->do ("CREATE TABLE studentTemp (num int, name varchar (10))"); if (!defined ($crTable)) { print ("error in creating table studentTemp $DBI::errstr \n"); } $rows = $dbh->do ("INSERT INTO studentTemp VALUES (1,". $dbh->quote ("Matt"). ")"); $rows = $dbh->do ("INSERT INTO studentTemp VALUES (2,". $dbh->quote ("Greg"). ")");

Murali Mani Perl DBI (contd…) $st = $dbh->prepare("SELECT * from studentTemp"); $st->execute(); print (" \n"); while ($data = $st->fetchrow_hashref()) { print " $data->{NUM} $data->{NAME} \n"; } print (" \n"); $st->finish(); $dbh->disconnect();

Murali Mani Perl with mySQL Everything stays the same except for the connect string – $dbh = DBI->connect ("DBI:mysql:$schema:$server", $userName, $passwd) || die "Database connection not made: $DBI::errstr";

Murali Mani Perl with HTML forms and Oracle #!/usr/local/bin/perl use CGI::Carp qw(fatalsToBrowser warningsToBrowser); use DBI; use configOracle; use CGI ":standard"; print "Content-type: text/html\n\n"; print (" Test Oracle - 2 \n"); print (" \n"); print (' '); if ($ENV{HTTP_ACCEPT}) { $ENV{ORACLE_HOME} = "/usr/local/oracle/product/11.1.0/db_1"; } $dbh = DBI->connect ("DBI:Oracle:host=$host;sid=$sid;port=$port", $userName,$passwd) || die "Database connection not made: $DBI::errstr";

Murali Mani Perl with HTML forms (contd..) if (defined (param ("submit"))) { $rows = $dbh->do ("INSERT INTO studentTemp VALUES (". $dbh->quote (param ("a1")). ", ". $dbh->quote (param ("a2")). ")"); if (! defined ($rows)) { print ("error inserting $DBI::errstr \n"); } } $st = $dbh->prepare("SELECT * from studentTemp"); $st->execute();

Murali Mani Perl with HTML forms (contd..) print (" \n"); print (" number name \n"); while ($data = $st->fetchrow_hashref()) { print " $data->{NUM} $data->{NAME} \n"; } print (" \n"); print <<ENDHTML; Num: Name: ENDHTML print (" \n"); $st->finish(); $dbh->disconnect();

Murali Mani Java Servlets Steps Install a web server, such as Apache Tomcat Learn about servlets Learn about HTML forms Learn how to use JDBC Integrate them into your project.

Murali Mani Installing a web server Download it from jakarta.apache.org/tomcat You might need about 50 MB of space for the installation For example, get the.tar.gz file (You may want to keep it in the temp directory, rather than your personal disk space). tar –xvzf file.tar.gz (untar it directly without unzipping it to save space).

Murali Mani Setting up the webserver I will call the root of the installation $TOMCAT_DIR In your.cshrc setenv TOMCAT_DIR /home/mmani/jakarta-tomcat Check the file $TOMCAT_DIR/conf/server.xml You will see a line <Connector port=“8080” You can renumber the port, say between 1200 and For your.cshrc setenv PATH ${PATH}:${TOMCAT_DIR}/bin setenv CLASSPATH ${CLASSPATH}:${TOMCAT_DIR}/common/lib/servlet- api.jar

Murali Mani Test the webserver Run the script startup.sh Open the page: You ran the startup.sh from ccc2 Your web server is configured to port 1200 (default was 8080) To check for errors etc, check $TOMCAT_DIR/logs To shut down, run the script shutdown.sh Check what processes are running: ps -u mmani Kill unnecessary Java processes: killall java

Murali Mani Servlets: Introduction Write the java code, and compile it. Configure the web server to recognize the servlet class. Restart the web server

Murali Mani First Java Servlet Check the directory $TOMCAT_DIR/webapps/servlets- examples/WEB-INF/classes There exist example servlets here Create a test servlet with the method doGet Compile it, let our test servlet be TestServlet.class

Murali Mani Configuring the web server Check $TOMCAT_DIR/webapps/servlets- examples/WEB-INF/web.xml Add the declarations MyTestServlet TestServlet MyTestServlet /servlet/FirstTestServlet

Murali Mani Test the servlet Restart the web server Go to the URL

Murali Mani JDBC: CLI (Call Level Interface) JDBC (Java Database Connetivity) is a standard API for connecting to databases from Java programs (such as servlets). Different vendors provide JDBC drivers implementing the JDBC API for different DBMS: Oracle, mySQL etc

Murali Mani Java Code with JDBC Steps import java.sql.* Load a driver instance Establish Connection Create a Statement Query

Murali Mani JDBC with Oracle JDBC driver comes with database server Check $ORACLE_HOME/jdbc/Readme.txt setenv CLASSPATH ${CLASSPATH}:${ORACLE_HOME}/jdbc/lib/ ojdbc6.jar

Murali Mani JDBC: Oracle Loading a Driver Class.forName (“oracle.jdbc.driver.OracleDriver”); Establishing a Connection Connection conn = oracle.wpi.edu:1521:WPIDBR2”,, ); Create a Statement Statement stmt = conn.createStatement ();

Murali Mani JDBC with mySQL You need to install the driver mySQL Connector/J from Setenv CLASSPATH /mysql-connector- java stable-bin.jar

Murali Mani JDBC: mySQL Loading a Driver Class.forName (“com.mysql.jdbc.Driver”); Establishing a Connection Connection conn = DriverManager.getConnection (“jdbc:mysql://mysql.wpi.edu/ ”,, ); Create a Statement Statement stmt = conn.createStatement ();

Murali Mani Queries using JDBC Queries: SQL DDL String sql = “CREATE TABLE a (a1 int, a2 int)”; stmt.executeUpdate (sql) Queries: SQL DML (Updates) String sql = “INSERT INTO a values (1, 1)”; stmt.executeUpdate (sql) Queries: SQL DML (Retrieval) String sql = “SELECT * FROM a”; ResultSet r = stmt.executeQuery (sql);

Murali Mani JDBC Result Set: Iteration We can iterate over a result set, r as: /* fetch the next tuple from r and ensure that it is not empty */ while (r.next ()) { System.out.println (“a1 = “ + r.getString (“a1”)); }

Murali Mani Close the statement and connection try { stmt.close (); } catch (SQLException sqlEx) { System.out.println (“Could not close statement:” + sqlEx.toString ()); try { conn.close (); } catch (SQLException sqlEx) { System.out.println (“Could not close connection:” + sqlEx.toString ());

Murali Mani Using Servlets with JDBC Ensure that the JDBC driver can be downloaded by our servlet. The servlet sees only the classes available at $TOMCAT_DIR/shared/lib $TOMCAT_DIR/common/lib Create a symbolic link, for example, for Oracle JDBC driver, from the directory $TOMCAT_DIR/shared/lib ln –s $ORACLE_HOME/jdbc/lib/ojdbc6.jar ojdbc6.jar