Database Programming Using JDBC and MySQL C API

Slides:



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

Basic JDBC Celsina Bignoli What is JDBC Industry standard for database- connectivity between the Java language and a wide range of.
1 Lecture 05: Database Programming (JDBC). 2 Outline JDBC overview JDBC API Reading: Chapter 10.5 PostgreSQL JDBC interface documentation
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.
JDBC CS-328. JDBC Java API for accessing RDBMS Allows use of SQL for RDBMS programming Can be used for: –embedded SQL –execution of stored queries.
1 JDBC Java Database Connectivity. 2 c.pdf
1 JDBC: Java Database Connectivity. 2 Introduction to JDBC JDBC is used for accessing databases from Java applications Information is transferred from.
JDBC Overview Autumn 2001 Lecturer: C. DeJong. Relational Databases widespread use used via SQL (Structured Query Language) freely available powerful.
UFCE4Y UFCE4Y-20-3 Components and Services Julia Dawson.
CIS 270—App Dev II Big Java Chapter 22 Relational Databases.
Database Processing with JSP ISYS 350. Example: Enter CID in a box and retrieve the customer record.
Overview of JDBC and Pro*C 1 Overview of JDBC,Pro*C and Oracle connectivity on Omega CSE 5330 – Database Systems.
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.
Beginning Databases with JDBC Mike Bradley Adapted from and notes by Kevin Parker, Ph.D.
JDBC and Hibernate Joshua Scotton. Connecting to Relational DBs.
Databases: Queries with Java Dr Andy Evans. JDBC SQL Three methods: Statements: Standard, simple, SQL. PreparedStatements: Compiled SQL statements that.
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.
Database Processing with JSP ISYS 350. Example: Enter CID in a box and retrieve the customer record.
CS 405G: Introduction to Database Systems Database programming.
Overview of JDBC and Pro*C 1 CSE 5330 – Database Systems.
1 JDBC Aum Amriteshwaryai Namah. 2 2 JDBC – Java DataBase Connectivity.
Chapter 8 Databases.
WEB/DB1 DATABASE PROGRAMMING 3JDBC by the ASU Scholars.
JDBC Session 2 Tonight’s topics: 1.Prepared Statements 2.Transaction Processing 3.Callable Statements & Stored Procedures 4.Scrollable & Updatable Result.
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.
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.
Web Design & Development 1 Lec Web Design & Development 2 More on JDBC.
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.
COMP 321 Week 4. Overview Normalization Entity-Relationship Diagrams SQL JDBC/JDBC Drivers hsqldb Lab 4-1 Introduction.
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)
Adv Java Chapter 1.JDBC Chapter 2.Servlets Chapter 3.JSP.
Database Management Systems 1 Raghu Ramakrishnan Database Application Development Chpt 6 Xin Zhang.
JDBC Java DataBase Connectivity. Loading the driver import java.sql.*... Class.forName("org.postgresql.Driver")‏
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.
Web Programming Assistant Professor Xiaozhong Liu
Introduction to JDBC Instructor: Mohamed Eltabakh 1.
1 JDBC – Java Database Connectivity CS , Spring 2010.
Intro to JDBC Joseph Sant Applied Computing and Engineering Sciences Sheridan ITAL.
JSP/Database Connectivity Instructor: Dr. M. Anwar Hossain.
Java Database Connectivity JDBC. Open Database Connectivity developed by Microsoft to provide interaction with databases using SQL. Use the JDBC-ODBC.
Java and database. 3 Relational Databases A relational Database consists of a set of simple rectangular tables or relations The column headings are.
JDBC Statements The JDBC Statement, CallableStatement, and PreparedStatement interfaces define the methods and properties that enables to send SQL or PL/SQL.
JDBC III IS Outline  Scrollable ResultSets  Updatable ResultSets  Prepared statements  Stored procedures.
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
CompSci 280 S Introduction to Software Development
JDBC and OCCI 10/29/2017.
Lec - 14.
Course Outcomes of Advanced Java Programming AJP (17625, C603)
JDBC – Java Database Connectivity
Advanced Web Automation Using Selenium
HW#4 Making Simple BBS Using JDBC
Prof: Dr. Shu-Ching Chen TA: Sheng Guan
JDBC – Java DataBase Connectivity
Database Management Systems
Client Access, Queries, Stored Procedures, JDBC
JDBC – Java DataBase Connectivity
Interacting with Database
JDBC – Java Database Connectivity
JDBC Example.
JDBC – Java DataBase Connectivity
Java Chapter 6 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

Database Programming Using JDBC and MySQL C API © Leonidas Fegaras University of Texas at Arlington

Database Connectivity with JDBC The JDBC API makes it possible to access databases and other data sources from Java import java.sql.*; ... Class.forName("com.mysql.jdbc.Driver").newInstance(); String jdbc = "jdbc:mysql://localhost:3306/db?user=smith&password=xxx"; Connection con = DriverManager.getConnection(jdbc); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("select * from employee"); while (rs.next())‏ System.out.println(rs.getString("fname")+" "+rs.getString("lname")); rs.close(); stmt.close(); con.close(); For updates/inserts/deletes, use stmt.executeUpdate(“update ...”); con.commit();

Working with ResultSet ResultSet: a table of data representing a database result set generated by executing a statement that queries the database It maintains a cursor pointing to its current row of data Initially the cursor is positioned before the first row The next method moves the cursor to the next row Provides getter methods for retrieving column values from the current row getString, getInt, getBoolean, getLong, ... Also provides setter methods for updating column values updateString, updateInt, ... Values can be retrieved/updated using either the index number of the column (starting from 1)‏ rs.getString(2) rs.updateString(2,“Smith”)‏ or the name of the column rs.getString(“name”) rs.updateString(“name”,“Smith”)‏

Updates To delete the current row from the ResultSet and from database rs.deleteRow(); To update a column value in the current row rs.updateString("name", "Smith"); rs.updateInt(“salary”,100000); rs.updateRow(); To insert column values into the insert row rs.moveToInsertRow(); rs.insertRow();

MySQL C API #include <stdlib.h> #include <stdio.h> #include <string.h> #include "mysql.h" MYSQL mysql; void check ( void* n ) { if (!n) { printf("MySQL error: %s\n",mysql_error(&mysql)); exit(-1); } int main ( int argc, char** argv ) { MYSQL_RES *result; MYSQL_ROW row; char* username = "fegaras"; char* password = "xxxx"; char* database = "fegaras"; if (mysql_init(&mysql)==NULL) { printf("\nFailed to start MySQL");

MySQL C API mysql_select_db(&mysql,database); check(mysql_connect(&mysql,"omega.uta.edu",username,password,NULL,0,NULL,0)); mysql_select_db(&mysql,database); mysql_query(&mysql,"select ssn from employee where lname='Smith'"); check(result = mysql_use_result(&mysql)); while ((row = mysql_fetch_row(result))) { printf("%d\n",row[0]); mysql_free_result(result); }; mysql_close(&mysql); }