Shane Cantrell Zach Crisman

Slides:



Advertisements
Similar presentations
CE203 - Application Programming Autumn 2013CE203 Part 51 Part 5.
Advertisements

J-Unit Framework.
Murach’s Java SE 6, C21© 2007, Mike Murach & Associates, Inc.Slide 1.
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.
 Pearson Education, Inc. All rights reserved Accessing Databases with JDBC.
Distributed Application Development B. Ramamurthy.
1 JDBC Java Database Connectivity. 2 c.pdf
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.
JDBC. In This Class We Will Cover: What SQL is What ODBC is What JDBC is JDBC basics Introduction to advanced JDBC topics.
1 Design patterns Lecture 4. 2 Three Important skills Understanding OO methodology Mastering Java language constructs Recognizing common problems and.
Presentation Outline What is JUnit? Why Use JUnit? JUnit Features Design of JUnit Downloading JUnit Writing Tests – TestCase – TestSuite Organizing The.
1 Foundations of Software Design Lecture 27: Java Database Programming Marti Hearst Fall 2002.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 37 Java Database Programming.
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
CSCI 6962: Server-side Design and Programming JDBC Database 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.
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.
Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.
CHAPTER 7 Database: SQL, MySQL. Topics  Introduction  Relational Database Model  Relational Database Overview: Books.mdb Database  SQL (Structured.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
CIS 270—Application Development II Chapter 25—Accessing Databases with JDBC.
Georgia Institute of Technology Making Text for the Web part 5 Barb Ericson Georgia Institute of Technology March 2006.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
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,
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.
Database Fred Durao What is a database? A database is any organized collection of data. Some examples of databases you may encounter in.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
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.
Stored procedures1 Stored procedures and functions Procedures and functions stored in the database.
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.
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.
JDBC. Preliminaries Database Database Collection of data Collection of data DBMS DBMS Database management system Database management system Stores and.
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.
JUnit Dwight Deugo Nesa Matic
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.
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.
Database Access Using JDBC BCIS 3680 Enterprise Programming.
JDBC CS 260 Database Systems. Overview  Introduction  JDBC driver types  Eclipse project setup  Programming with JDBC  Prepared statements  SQL.
Access Databases from Java Programs via JDBC Tessema M. Mengistu Department of Computer Science Southern Illinois University Carbondale
Basics of JDBC Session 14.
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,
JDBC - Resultset The java.sql.ResultSet interface represents the result set of a database query. A ResultSet object maintains a cursor that points to the.
Introduction to JDBC Instructor: Mohamed Eltabakh 1.
Test Automation For Web-Based Applications Portnov Computer School Presenter: Ellie Skobel.
1 JDBC – Java Database Connectivity CS , Spring 2010.
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.
CS422 Principles of Database Systems JDBC and Embedded SQL Chengyu Sun California State University, Los Angeles.
DEPTT. OF COMP. SC & APPLICATIONS
Note: To complete the examples in this section you need access to a database!! Most of the examples work for any database with JDBC drivers. However, connecting.
Lec - 14.
JDBC – Java Database Connectivity
HW#4 Making Simple BBS Using JDBC
JDBC.
MS Access Database Connection
Introduction to Server-Side Web Development using JSP and Databases
Objectives In this lesson, you will learn about:
Interacting with Database
MSIS 655 Advanced Business Applications Programming
Java Database Connectivity
Introduction To Structured Query Language (SQL)
JDBC Example.
JUnit Tutorial Hong Qing Yu Nov 2005.
Java Chapter 6 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

Shane Cantrell Zach Crisman Unit Testing and SQL Shane Cantrell Zach Crisman

Resources JUnit SQL http://www.junit.org/index.htm http://sourceforge.net/projects/junit http://junit.sourceforge.net/doc/testinfected/testing.htm SQL http://www.w3schools.com/sql/default.asp http://shane.hydrus.net/cse403/MyDatabase.zip

Why Test? Gets you to think about possible modes of failure Allows you to easily verify that nothing has been inadvertently broken If something breaks, then you know right away (assuming it was covered in a test) Allows test code to be conveniently packaged for continued use

JUnit: Planning Initialize test variables Run the test Create the solution using a direct method Compare the results Classes should be designed with unit testing in mind!

JUnit: Basic Steps Extend class TestCase Keep it in the same package as the classes to be tested, so that it can access package private methods Create public functions to test each case Create the “public static Test suite()” function, which returns a suite containing your test functions

JUnit: Example Skeleton public class MyTest extends TestCase { protected void setUp() { ... } protected void tearDown() { ... } public static Test suite() { ... } }

JUnit: Example suite() public class MoneyTest extends TestCase { ... public static Test suite() { TestSuite suite = new TestSuite(); suite.addTest(new MoneyTest(“testEquals”)); suite.addTest(new MoneyTest(“testSimpleAdd”)); return suite; }

JUnit: Class Assert assertEqual(expected, actual) assertTrue(boolean) assertFalse(boolean) assertNull(object) assertNotNull(object) assertSame(expected, actual) assertNotSame(expected, actual)

JUnit: Example Class public class MathTest extends TestCase { protected double fValue1; protected double fValue2; protected void setUp() { fValue1 = 2.0; fValue2 = 3.0; } public void testAdd() { double result = fValue1 + fValue2; assertTrue(result == 5.0); ...

JUnit: Running Tests java junit.textui.TestRunner junit.samples.AllTests java junit.swingui.TestRunner junit.samples.AllTests

SQL: What is it? SQL (Structured Query Language) SQL Databases ANSI language for interfacing databases Uses very simple text commands SQL Databases Organization is similar to a bunch of linked spreadsheets called “tables” Store text, numbers, etc. Most have their own proprietary extensions

SQL: Tables Creating Deleting CREATE TABLE tableName ( columnName1 type, columnName2 type, ... ) Ex: CREATE TABLE objects ( objID int, name varchar(80) ) Deleting DROP TABLE tableName Ex: DROP TABLE objects

SQL: Inserting Data Insert a Row Update a Cell Delete a Row INSERT INTO tableName ( columnName1, ..., columnNameN ) VALUES ( value1, ..., valueN ) Ex: INSERT INTO objects ( objID, name ) VALUES ( 0, ‘void’ ) Update a Cell UPDATE tableName SET columnName1 = value1, ..., columnNameN = valueN WHERE criteria Ex: UPDATE objects SET name = ‘apple’ WHERE objID = 0 Delete a Row DELETE FROM tableName WHERE criteria Ex: DELETE FROM objects WHERE objID = 0

SQL: Finding Data Basic Usage Specifiers SELECT columnName1, ..., columnNameN FROM tableName Ex: SELECT objID, name FROM objects Specifiers WHERE (criteria for selecting rows) WHERE criteria WHERE columnName = value WHERE columnName > value AND criteria WHERE columnName LIKE value GROUP BY (criteria for grouping rows) ORDER BY (criteria for ordering rows) ORDER BY columnName1, ..., columnNameN ORDER BY columnName1 ASC, ..., columnNameN DESC INNER JOIN (merge rows from multiple tables)

SQL: What You Need SQL Driver URL Username Password org.postgresql.Driver URL jdbc:postgresql://cubist.cs.washington.edu/shanec Username Password Restart Tomcat to get an updated Java classpath

JDBC and SQL package java.sql.* java.lang.Class DriverManager Connection Statement ResultSet ResultSetMetaData SQLException java.lang.Class

Loading the Driver Class.forName(JDBC_DRIVER); Connection connection = DriverManager.getConnection(DATABASE_URL, DATABASE_USERNAME, DATABASE_PASSWORD); JDBC_DRIVER = “org.postgresql.Driver” DATABASE_URL = “jdbc:postgresql://cubist.cs.washington.edu/shanec” DATABASE_USERNAME = “shanec” DATABASE_PASSWORD = “pwd”

Sending Commands Statement statement; statement = connection.createStatement(); statement.execute(“ ... ”); ResultSet resultSet = statement.executeQuery(“ ... ”);

Important Points ResultSet Only one per statement object Close automatically with closure of statement or new statement method call Must advance to the first row before accessing data Column indices start with one

Other: POSTing Files <FORM ENCTYPE="multipart/form-data“ http://snowwhite.it.brighton.ac.uk/~mas/mas/courses/html/html.html <FORM ENCTYPE="multipart/form-data“ ACTION="URL“ METHOD=POST> Send file name:<BR> <INPUT NAME="message“ TYPE="file"> <BR> <BR> <INPUT TYPE="submit“ VALUE="Send file to server"> </FORM>

Reminder Unit Testing Logging (java.util.logging) Jakarta Libraries CVS E-Mail Lists Bug Tracking

Next Week Discussion on testing and debugging! Think about what Ian King has to say. Do you agree or disagree? How does your testing compare? Do you have testing stories from your past?