Making Text for the Web part 6

Slides:



Advertisements
Similar presentations
Java Database Connectivity (JDBC). 2/24 JDBC (Java DataBase Connectivity) - provides access to relational database systems JDBC is a vendor independent.
Advertisements

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 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.
Georgia Institute of Technology Making Text for the Web part 4 Barb Ericson Georgia Institute of Technology March 2006.
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.
JAVA JDBC JAVA JDBC Java Database Programming Lamiaa Said.
Georgia Institute of Technology Speed part 3 Barb Ericson Georgia Institute of Technology May 2006.
Georgia Institute of Technology Creating and Modifying Text part 4 Barb Ericson Georgia Institute of Technology Oct 2005.
Examples of Using Servlets and JSP Representation and Management of Data on the Internet.
Java Servlets and Java Server Pages Carol Wolf Computer Science.
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.
Java Server Pages A JSP page is a text-based document that contains two types of text: static template data, which can be expressed in any text-based format,
Dr. Magdi AMER Unit 2 Introduction to Database. Intro Many programs need to save information on disk. The role of DB system is to provide a layer of abstraction.
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.
JDBC Tutorial MIE456 - Information Systems Infrastructure II Vinod Muthusamy November 4, 2004.
JAVA Database Access. JDBC The Java Database Connectivity (JDBC) API is the industry standard for database- independent connectivity between the Java.
MDCFUG Is Java in Your Future? Tyler Williams Principal dataTerrace
Mark Dixon 1 09 – Java Servlets. Mark Dixon 2 Session Aims & Objectives Aims –To cover a range of web-application design techniques Objectives, by end.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 32.1 Reviewing the Bookstore Application 32.2.
CS 160: Software Engineering October 1 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
CPSC1301 Computer Science 1 Chapter 12 Creating and Modifying Text part 4.
Georgia Institute of Technology Making Text for the Web Barb Ericson Georgia Institute of Technology March 2006.
Java Classes ISYS 350. Introduction to Classes A class is the blueprint for an object. – It describes a particular type of object. – It specifies the.
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.
Java and Databases. JDBC Architecture Java Application JDBC API Data Base Drivers AccessSQL Server DB2InformixMySQLSybase.
CIS 234: Java Methods Dr. Ralph D. Westfall April, 2010.
Mark Dixon 1 11 – Java Servlets. Mark Dixon 2 Session Aims & Objectives Aims –To cover a range of web-application design techniques Objectives, by end.
CreatingClasses-SlideShow-part31 Creating Classes part 3 Barb Ericson Georgia Institute of Technology Dec 2009.
JAVA BEANS JSP - Standard Tag Library (JSTL) JAVA Enterprise Edition.
Georgia Institute of Technology What is new in Java 5.0 (1.5)? Barb Ericson Georgia Institute of Technology June 2006.
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.
Web Programming Assistant Professor Xiaozhong Liu
SourceAnatomy1 Java Source Anatomy Barb Ericson Georgia Institute of Technology July 2008.
Georgia Institute of Technology Making Text for the Web part 2 Barb Ericson Georgia Institute of Technology March 2006.
Intro to JDBC Joseph Sant Applied Computing and Engineering Sciences Sheridan ITAL.
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.
17 Copyright © 2004, Oracle. All rights reserved. Integrating J2EE Components.
Database Processing with JSP ISYS 350. Database Applications Applications Database Server Queries/Updates Results.
JDBC.
A Presentation Presentation On JSP On JSP & Online Shopping Cart Online Shopping Cart.
CS 562 Advanced Java and Internet Application Computer Warehouse Web Application By Team Alpha :-  Puja Mehta (102163)  Mona Nagpure (102147)
Georgia Institute of Technology Making Text for the Web part 3 Barb Ericson Georgia Institute of Technology March 2006.
JSP java server pages.
JDBC 15-Apr-18.
Sixth Lecture ArrayList Abstract Class and Interface
CS320 Web and Internet Programming Database Access with JDBC
How to connect natively?
Barb Ericson Georgia Institute of Technology May 2006
Advanced Web Automation Using Selenium
JDBC 21-Aug-18.
HW#4 Making Simple BBS Using JDBC
JDBC.
Creating and Modifying Text part 2
Prof: Dr. Shu-Ching Chen TA: Sheng Guan
JDBC 15-Nov-18.
Super Market Management
Using a Database with JDBC
Workshop for Programming And Systems Management Teachers
Constructors, GUI’s(Using Swing) and ActionListner
JAVA DATABaSE CONNECTIVITY
Barb Ericson Georgia Institute of Technology June 2005
JDBC Example.
Lecture 11 Database Connection
Creating and Modifying Text part 3
Barb Ericson Georgia Institute of Technology Oct 2005
Barb Ericson Georgia Institute of Technology May 2006
Java Chapter 6 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

Making Text for the Web part 6 Barb Ericson Georgia Institute of Technology March 2006 Georgia Institute of Technology

Georgia Institute of Technology Doing a Join Query Add aliases for the table names Picture as pict, Person as per, PicturePerson as pictPer Use the alias in front of the field name per.FirstName, pict.FileName Use And to join conditions Where per.firstName = 'Jennifer' And pictPer.PersonID = per.PersonID And pict.PictureID = pictPer.PictureID Georgia Institute of Technology

Georgia Institute of Technology Finding Jennifer /* main for testing */ public static void main(String[] args) { // create the database manager for an Access database DatabaseManager dbManager = new DatabaseManager("sun.jdbc.odbc.JdbcOdbcDriver", "jdbc:odbc:person"); // create the database manager for a MySQL database // new DatabaseManager("com.mysql.jdbc.Driver", // "jdbc:mysql://localhost:3306/person"); // test a query dbManager.testQuery("Select per.FirstName, " + "pict.FileName From " + "Picture as pict, Person as per, " + "PicturePerson as pictPer " + "Where per.FirstName = 'Jennifer' And " + "pictPer.PersonID = per.PersonID And " + "pict.PictureID = pictPer.PictureID", 2); } Georgia Institute of Technology

Getting a String for a Query /** * Method to execute a query and return a string of the * first result * @param query the query to execute * @return the first result of the query, or null if none */ public String getStringForQuery(String query) { String result = null; // try the following try { // open the connection to the database Connection connection = DriverManager.getConnection(this.urlStr); // create a statement Statement statement = connection.createStatement(); // execute the query ResultSet rs = statement.executeQuery(query); // print out the results if (rs.next()) { result = rs.getString(1); } // close everything rs.close(); statement.close(); connection.close(); } catch (SQLException ex) { SimpleOutput.showError("Trouble with the database " + urlStr); ex.printStackTrace(); return result; Georgia Institute of Technology

Adding Database Info to a Homepage Now we can use a database to get information for an HTML page Modify the writeHomepage method to get the person's age from the database Use the DatabaseManager class to get it Georgia Institute of Technology

Write Homepage with Database Info /** * Method for writing a homepage for the passed * first name that displays her/his interests and age * @param name the person's first name * @param interests a list of the person's interests */ public void writeHomepageV5(String name, String interests) { // Get a DatabaseManager object DatabaseManager dbManager = new DatabaseManager("sun.jdbc.odbc.JdbcOdbcDriver", "jdbc:odbc:person"); // get this person's age String age = dbManager.getStringForQuery( "Select Age From Person " + "Where FirstName='" + name + "'"); // try the following try { // open a file for writing BufferedWriter writer = new BufferedWriter(new FileWriter(name + ".html")); // write the start writeStart(writer); // write the header writeHead(writer,name + "'s Homepage"); // write the body writeBody(writer,"<h1>Welcome to " + name + "'s Homepage</h1>" + "<p> I am interested in " + interests + ".</p><p>I am " + age + " years old</p>"); // end the page writeEnd(writer); // close the writer writer.close(); } catch (Exception ex) { ex.printStackTrace(); } Georgia Institute of Technology

Testing the Homepage Writer public static void main(String[] args) { WebPageWriter writer = new WebPageWriter(); writer.writeHomepageV5("Matthew", "playing video games"); } Georgia Institute of Technology

Georgia Institute of Technology Exercise Create a writeHomepageV6 method that looks up the person's name in the database and adds thumbnails of pictures of that person to the page Add information to the database for your pictures Add to the Person table Add to the Picture table Add to the PicturePerson table Use the writeHomepage method to generate a homepage for you With your pictures on it Georgia Institute of Technology

Georgia Institute of Technology Servlets and JSP Some database access is done through JavaServer Pages (JSPs) HTML pages with special tags that allow Java code to be executed JSP pages are translated into servlets Small programs like applets But they run on the server Servlets connect to the database and get information Which is displayed in the HTML Georgia Institute of Technology

Georgia Institute of Technology Summary HTML is the language of the Web Not a programming language You can use Java programs to create HTML Helper methods are often private methods that are used by other public methods To break a task into parts (procedural abstraction) Throwing an exception A method can throw an exception using the throws keyword followed by the exception name The Unnamed Package All classes are put in a package. If you don't specify a package the "unnamed" one is used Georgia Institute of Technology

Georgia Institute of Technology Summary Continued Maps store key and value pairs Map is an interface HashMap, Hashtable, and TreeMap are classes that implement Map Generics allow you to declare the types of things in collection classes and eliminate the need to downcast when you take items back out of a collection Iterators let you walk through each item in a collection Using classes in the java.sql package you can access information in a database SQL is the standard language to use to communicate with a database Georgia Institute of Technology