140 likes | 290 Views
Web Application Development. Database-backed Web Application Programming. Muhammad Ali Versonic Pte Asher Imtiaz Forman Christian College. Agenda. MySQL MySQL GUI JDBC Writing a Student CRUD. Web Application Development. Database Connectivity with MySQL. Muhammad Ali Versonic Pte
E N D
Web Application Development Database-backed Web Application Programming Muhammad Ali Versonic Pte Asher Imtiaz Forman Christian College
Agenda • MySQL • MySQL GUI • JDBC • Writing a Student CRUD
Web Application Development Database Connectivity with MySQL Muhammad Ali Versonic Pte Asher Imtiaz Forman Christian College
MySQL • Full-featured Database Management System • Most popular for Web applications • Over 6 million installations • Over 20 OS are supported • Libraries for accessing MySQL are available in all major programming languages • Used in high scale WWW products including Google, Wikipedia and Facebook http://en.wikipedia.org/wiki/MySQL
Partial Student Table for FCC-SAMS DB • Roll Number • First Name • Last Name • Gender • Address • Email • Phone • CGPA
SQLYog • Graphical User Interface (GUI) tool for MySQL • Created by Webyog, based in Bangalore, India. • DEMO with the Implementation http://en.wikipedia.org/wiki/SQLyog
Java Database Connectivity(JDBC) • An API for Java programming language • Define how a client may access a DB • Provides methods for querying and updating data in a DB http://en.wikipedia.org/wiki/Java_Database_Connectivity
The Java JDBC Architecture • JDBC is a ‘standard’ API programmers use to access database systems • Various JDBC drivers are available that interface with particular database systems • A few database systems (HSQLDB and Derby) use JDBC as their native API
Database Access Architecture • Point: Translation to vendor format is performed on the client • No changes needed to server • Driver (translator) needed on client Slide Credit: Programming the World Wide Web Book by Sebesta
JDBC Data Types Slide Credit: Marty Hall www.coreservlets.com
Steps o) Import Package – java.sql package. • Load the driver • Not required in Java 6, so Java 6 needs only 6 steps. • Define the Connection URL • Establish the Connection • Create a Statement object • Execute a query • Process the results • Close the connection Slide Credit: Marty Hall www.coreservlets.com
Steps 3 6 1 DriverManager ResultSet Connection Statement creates creates creates 5 4 SQL Data 2 Establish Link To DB Driver Database Slide Credit: Umair Javed, LUMS
Connection URL • The database connection URL is specified by a string of the form jdbc:subprotocol_name:more_info • The subprotocol name is mysql for MySQL • other_info might include the database name and a query string providing values such as a username or password
// Class.forName("com.mysql.jdbc.Driver"); Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306", "root", "abc"); Statement statement = connection.createStatement(); introwCount = statement.executeUpdate(“INSERT INTO sams_student(std_roll_number, std_name) VALUES(‘11-10307’, ‘Ahmed’)”); connection.close();