Web Programming Assistant Professor Xiaozhong Liu

Slides:



Advertisements
Similar presentations
JDBC – Java DataBase Connectivity CSE432 Object Oriented Software Engineering.
Advertisements

19 augustus 2003augustus 2003 JSP-2. BICT 2JDBC BICT 3Install MySQL Download MySQL daemon – Free – Windows version… Start Daemon – Mysqld-nt.exe Download.
Basic JDBC Celsina Bignoli What is JDBC Industry standard for database- connectivity between the Java language and a wide range of.
1 JDBC: Java Database Connectivity. 2 Introduction to JDBC JDBC is used for accessing databases from Java applications Information is transferred from.
Java Database Connectivity JDBC ICW Lecture 12 Errol Thompson.
Java database Programming JDBC Trademarked name of a Java API that supports Java programs that access relational databases Stand for Java DataBase Connectivity.
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.
CS178 Database Management “JDBC”. What is JDBC ? JDBC stands for “Java DataBase Connectivity” The standard interface for communication between a Java.
JDBC. What is JDBC JDBC is an acronym for –Java Data Base Connectivity. It allows java/jsp program to connect to any database.
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.
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.
JDBC (Java Database Connectivity) SNU OOPSLA Lab. October 2005.
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui COMP 302 Database Systems Java Data Base Connectivity Lecturer Dr Pavle Mogin.
Database Processing with JSP ISYS 350. Example: Enter CID in a box and retrieve the customer record.
Servlets Database Access. Agenda:  Setup Java Environment  Install Database  Install Database Drivers  Create Table and add records  Accessing a.
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.
CS 160: Software Engineering October 1 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
Index and JDBC/JSP tutorial Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
JDBC. Preliminaries Database Database Collection of data Collection of data DBMS DBMS Database management system Database management system Stores and.
Chapter 8 Databases.
Accessing Database using JDBC. JDBC Objectives Gain basic knowledge of Java JDBC Become familiar with the basics of interacting with a database using.
WEB/DB1 DATABASE PROGRAMMING 3JDBC by the ASU Scholars.
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.
Li Tak Sing COMPS311F. Database programming JDBC (Java Database Connectivity) Java version of ODBC (Open Database Connectivity) ODBC provides a standard.
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.
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.
Basics of JDBC.
JDBC (Java Database Connectivity)
Advanced Java Session 5 New York University School of Continuing and Professional Studies.
Database Programming With Java & JDBC Reading: DD Ch. 18, pp al/jdbc/index.html, or anything covering JDBC.
Umair Javed©2005 Enterprise Application Development Java Database Connectivity (JDBC) JDBC1.
Introduction to JDBC Instructor: Mohamed Eltabakh 1.
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.
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.
JSP/Database Connectivity Instructor: Dr. M. Anwar Hossain.
Java and database. 3 Relational Databases A relational Database consists of a set of simple rectangular tables or relations The column headings are.
JDBC.
JDBC Java Data Base Connectivity נערך ע"י: אורי רוטנברג הנחיה: ד"ר תמר בניה קורס: סדנא ב-Java.
CS 562 Advanced Java and Internet Application Computer Warehouse Web Application By Team Alpha :-  Puja Mehta (102163)  Mona Nagpure (102147)
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.
MySQL root 암호 $ mysqladmin -u root -p password new-password $ mysql -u root mysql mysql> update user set password = password('new-password') where user.
JDBC – Java DataBase Connectivity
JSP and DB.
CompSci 280 S Introduction to Software Development
CS3220 Web and Internet Programming Database Access with JDBC
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.
Course Outcomes of Advanced Java Programming AJP (17625, C603)
Web Technologies IT230 Dr Mohamed Habib.
CS320 Web and Internet Programming Database Access with JDBC
Advanced Web Automation Using Selenium
HW#4 Making Simple BBS Using JDBC
JDBC – Java DataBase Connectivity
Client Access, Queries, Stored Procedures, JDBC
JDBC – Java DataBase Connectivity
Introduction to Server-Side Web Development using JSP and Databases
Using a Database with JDBC
JDBC API.
JDBC Example.
CS3220 Web and Internet Programming Database Access with JDBC
CS3220 Web and Internet Programming Database Access with JDBC
JDBC – Java DataBase Connectivity
Presentation transcript:

Web Programming Assistant Professor Xiaozhong Liu

Compare Read from File Write to File FileReader file = new FileReader("test.txt"); Scanner s = new Scanner(reader); while( s.hasNext()) { System.out.println(s.next()); } s.close(); BufferedReader reader = new BufferedReader(file); FileWriter file = new FileWriter("test.txt"); writer.write(“Hello, I’m writing…”); writer.close(); BufferedWriter writer = new BufferedReader(file);

Servlet + File Compute test Please submit your information First number: Second number: web.html copy to project folder/WebContent/

Servlet + File protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String path = "/web.html"; request.getRequestDispatcher(path).forward(request, response); } load the html or jsp file from hard drive

Scope of variables public class test { String name; int time; public void connect () { int age; String name; for (int i = 0; i < 5; i++) { String bookname; }

Scope of variables public class test { String name; int time; public void connect () { int age; String name; for (int i = 0; i < 5; i++) { String bookname; } Class global variable: belongs to the class local variable: belongs to the method temp variable: belongs to the loop

Information problem… Input Output jTextField GUI Servlet File? Database? Internet? Error???

Database: Table Fields (of table)Type: String Type: int Data

Java open DB Java JDBC (Java Database Connectivity) Database Jar, complied Java classes

Java open DB

Java operates DB 1.Establish a connection (Connection class) 2.Create JDBC Statements (Statement class) 3.Execute SQL Statements (stmtement.executeUpdate…) 4.GET ResultSet (ResultSet class) 5.Close connections

Java – DB Connection import java.sql.*; Load the vendor specific driver Class.forName("oracle.jdbc.driver.OracleDriver"); // for Oracle database Class.forName("org.gjt.mm.mysql.Driver"); // for MYSQL database Make the connection Connection con = DriverManager.getConnection(…);

Java open DB Connection connection; Statement statement = null; Class.forName("org.gjt.mm.mysql.Driver"); String url = "jdbc:mysql://rdc04.uits.iu.edu:3264/S517DB"; String username = "S517"; String password = "S517"; connection = DriverManager.getConnection (url, username, password); statement = connection.createStatement();

Java open DB String url = "jdbc:mysql://rdc04.uits.iu.edu:3264/S517DB”; Server Address Port Number on DB server DB name

Java read from DB ResultSet rs = statement.executeQuery("select * from user"); while (rs.next()) { //Read each record int ID = rs.getInt("ID"); String firstname = rs.getString("Firstname"); String lastname = rs.getString("Lastname"); int age = rs.getInt("Age"); String gender = rs.getString("gender"); System.out.println(ID + "\t" + firstname + "\t"+ lastname + "\t" + age + "\t" + gender + "\t"); } rs.close(); statement.close(); connection.close();

Java read from DB rs.previous(); / / go back in the RS rs.relative(-5); / / go 5 records back rs.relative(7); / / go 7 records forward rs.absolute(100); / / go to 100th record

Java DB update Connection connection = DriverManager.getConnection (url, username, password); Statement statement = connection.createStatement(); statement.executeUpdate("insert into sometable…"); //shows how many rows are affected statement.close(); connection.close(); Insert, Delete, Update…

Basic DB search query Select * from user // Get all the record from user table Select Firstname, age, gender from user // Get Firstname, age, gender fields for all the record from user table Select * from user where age > 15 // Get all the record from user table where age larger than 15 Select * from user where Firstname = ‘Jenny’ // Get all the record from user table where Firstname is ‘Jenny’

DB Transaction Transaction control can be implemented by the Connection object, default mode is auto-commit, (each sql statement is treated as a transaction) We can turn off the auto-commit mode with con.setAutoCommit(false); Or turn on by con.setAutoCommit(true); If auto-commit is off, no SQL statement will be committed until - con.commit();

DB Metadata Statement stmt = conn.createStatement(); ResultSet resultSet = stmt.executeQuery("SELECT * FROM student"); ResultSetMetaData md = resultSet.getMetaData(); for (int i = 1; i <= md.getColumnCount(); i++) System.out.print(md.getColumnLabel(i) + " "); System.out.println(); while (resultSet.next()) { for (int i = 1; i <= md.getColumnCount(); i++) System.out.print(resultSet.getString(i) + " "); System.out.println(); }