MySQL, Java, and JDBC CSE 3330 Southern Methodist University.

Slides:



Advertisements
Similar presentations
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.
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 Lecture 05: Database Programming (JDBC). 2 Outline JDBC overview JDBC API Reading: Chapter 10.5 Pointbase Developer Manual.
JDBC. JDBC (Java Database Connectivity): JDBC is an API for the Java programming language that defines how a client may access a database. It provides.
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.
Advanced Java Programming – Eran Toch Methodologies in Information System Development Tutorial: Advanced Java Programming and Database connection Eran.
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 …
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.
Java MS Access database connectivity Follow these steps: 1)Go to the start->Control Panel->Administrative Tools- > data sources. 2)Click Add button and.
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
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.
Views, Indexes and JDBC/JSP tutorial Professor: Dr. Shu-Ching Chen TA: Haiman Tian 1.
 2004 Keith Vander Linden. All Rights Reserved. Calvin CollegeDepartment of Computer Science(1/25) Database Programming with JDBC Keith Vander Linden.
JDBC Tutorial MIE456 - Information Systems Infrastructure II Vinod Muthusamy November 4, 2004.
JDBC (Java Database Connectivity) SNU OOPSLA Lab. October 2005.
JAVA Database Access. JDBC The Java Database Connectivity (JDBC) API is the industry standard for database- independent connectivity between the Java.
Servlets Database Access. Agenda:  Setup Java Environment  Install Database  Install Database Drivers  Create Table and add records  Accessing a.
 What software components are required?  How do I install the Oracle JDBC driver?  How do I connect to the database?  What form is the data in and.
CS 160: Software Engineering October 1 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
JDBC Java and Databases. RHS – SOC 2 JDBC JDBC – Java DataBase Connectivity An API (i.e. a set of classes and methods), for working with databases in.
Index and JDBC/JSP tutorial Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
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.
JDBC. A Basic MySQL Tutorial MySQL is an open source database management software that helps users store, organize, and retrieve data. It is a very powerful.
Chapter 25 Databases. Chapter Scope Database concepts Tables and queries SQL statements Managing data in a database Java Foundations, 3rd Edition, Lewis/DePasquale/Chase25.
Copyright  Oracle Corporation, All rights reserved. 7 Accessing a Database Using SQLJ.
Java Database Connectivity. Java and the database Database is used to store data. It is also known as persistent storage as the data is stored and can.
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.
COMP 321 Week 4. Overview Normalization Entity-Relationship Diagrams SQL JDBC/JDBC Drivers hsqldb Lab 4-1 Introduction.
DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of.
EXAMPLE I An application showing JDBC access to Cloudscape.
JDBC and SQLJ CIS 612 Spring JDBC JDBC is an API that enables database access from Java programs JDBC for DB access provides ◦ Portability across.
Tasks Needed for MissionMapEditor Martin Q. Zhao September 18, 2010.
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.
Access Databases from Java Programs via JDBC Tessema M. Mengistu Department of Computer Science Southern Illinois University Carbondale
Basics of JDBC.
JDBC (Java Database Connectivity)
JAVA DATABASE OOP Praktek dengan Java Miswar,S.st Sumber : Eddy Muntina Dharma,ST,MT.
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.
1 JDBC – Java Database Connectivity CS , Spring 2010.
1 Download current version of Tomcat from: g/tomcat/ g/tomcat/ Install it in: C:\Program Files\Apache.
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.
Using Oracle JDBC How to Run JDBC on Your Account Communication Mechanism Using Metadata Building a Database Auto Commit v.s Atomic Transaction.
JSP/Database Connectivity Instructor: Dr. M. Anwar Hossain.
CS422 Principles of Database Systems JDBC and Embedded SQL Chengyu Sun California State University, Los Angeles.
CSC 411/511: DBMS Design Dr. Nan WangCSC411_L12_Oracle10g_JDBC 1 Application Development (JDBC)
JDBC. What is JDBC JDBC is an acronym for –Java Data Base Connectivity. It allows java program to connect to any database.
1. Writing a Java program to connect to SQL Server 2008 and Create a table Populate the table (insert data) Perform queries to retrieve information from.
CS320 Web and Internet Programming Database Access with JDBC Chengyu Sun California State University, Los Angeles.
MYSQL APPLICATIONS USING JAVA & JDBC CIS 430 –Database Concepts Victor Matos.
JDBC and OCCI 10/29/2017.
Lec - 14.
JDBC 15-Apr-18.
JDBC – Java Database Connectivity
CS320 Web and Internet Programming Database Access with JDBC
Advanced Web Automation Using Selenium
JDBC 21-Aug-18.
HW#4 Making Simple BBS Using JDBC
Prof: Dr. Shu-Ching Chen TA: Sheng Guan
JDBC 15-Nov-18.
MSIS 655 Advanced Business Applications Programming
Using a Database with JDBC
JDBC Example.
Presentation transcript:

MySQL, Java, and JDBC CSE 3330 Southern Methodist University

Question When’s the last time you pulled up Amazon.com and typed in an SQL Query directly? How about with Access.SMU? Issued any SQL Queries directly recently?

Accessing MySQL We need a way to access from a programming languages Various ways to do this in different languages Java uses the JDBC API – JDBC = Java Database Connectivity – Allows standardized access to relational databases from Java

Overview Java-based Application MySQL Connector/J MySQL DBMS

JDBC JDBC standardizes: – Initiating a connection to a RDBMS – Creating a SQL statement for later execution – Executing a SQL statement against the RDBMS – Retrieving the result of a query (if applicable) MySQL’s Connector/J – Type 4 JDBC Driver – All Java/Native protocol driver

JDBC Some Important JDBC API classes: – Driver Manager – Connection – Statement – ResultSet – SQLException

In your IDE Create a new Project called JDBCTest Add MySql JDBC Driver to your “libraries” that are used in compiling – In Netbeans, go to project properties, choose libraries on left, and select the aforementioned driver Create an empty Java source file – import java.sql.*; – add a main method to the file.

public static void main (String [] args) { try { Class.forName("com.mysql.jdbc.Driver"); Connection conn = DriverManager.getConnection( "jdbc:mysql://localhost/cse3330a?”+ “user=root&password=aSecret123" ); Statement stmt = conn.createStatement(); ResultSetrs = stmt.executeQuery("SELECT * FROM classes"); while (rs.next()){ System.out.println(rs.getString("prof")); } rs.close(); stmt.close(); conn.close(); } catch (Exception e) { System.out.println(e.getMessage()); } Overview DOES NOT WORK; Get Main.java example From

Step 1) Load the MySQL JDBC Driver Class.forName("com.mysql.jdbc.Driver");

Step 2) Create a Connection Connection conn = DriverManager.getConnection( "jdbc:mysql://localhost/cse3330a?”+ “user=root&password=aSecret123”); Server Database Username Password

Step 3) Create Statement and Execute SQL Query Statement stmt = conn.createStatement(); ResultSetrs = stmt.executeQuery( "SELECT * FROM classes");

Step 4) Iterate over Results Imagine result set is a “table” or grid with each column having a name while (rs.next()){ System.out.println(rs.getString("prof")); }

Step 5) Clean Up rs.close(); stmt.close(); conn.close(); Note – Reverse Order

In-Class Exercise Write a program that will: – Allow the user to enter their student id – Show a list of classes to the user (SELECT) – Allow the user to “register” for a class (INSERT) Log in to MySQL directly to make sure the insert took place. Don’t worry about details like double registering or overlapping times (esp. since we’re not storing times)