Q7M1 – SC Dudy Fathan Ali S.Kom
Java CRUD Mechanism
with SQL Server Database
Q7M1
Dudy Fathan Ali, S.Kom (DFA)
2017
CEP - CCIT
Fakultas Teknik Universitas Indonesia
Repository
Q7M1 – SC Dudy Fathan Ali S.Kom
http://bit.ly/4sc5-repo
Download Presentation Slide
Create a Database in SQL Server
Q7M1 – SC Dudy Fathan Ali S.Kom
To follow this lesson, you need to create a database based on the
following schematic database diagram:
Database name: GoShop
Configuring JDBC-ODBC Data Source Name
Q7M1 – SC Dudy Fathan Ali S.Kom
You need to perform the following steps to create a Data Source
Name:
o Select the required driver for a DSN
o Specifying the connection details for a DSN
o Testing the created DSN
Configuring JDBC-ODBC Data Source Name
Q7M1 – SC Dudy Fathan Ali S.Kom
Selecting the required driver for a DSN
o Open Administrative Tools in
Control Panel
o Double-click the ODBC Data
Sources Icon
Configuring JDBC-ODBC Data Source Name
Q7M1 – SC Dudy Fathan Ali S.Kom
Selecting the required driver for a DSN
o Select System DSN Tab
o Add New System Data Sources
Configuring JDBC-ODBC Data Source Name
Q7M1 – SC Dudy Fathan Ali S.Kom
Selecting the required driver for a DSN
o In the Create New Data Source
dialog box, select SQL Server
option
o Click the Finish button
Configuring JDBC-ODBC Data Source Name
Q7M1 – SC Dudy Fathan Ali S.Kom
Specifying the connection details for a DSN
o Type the name of the Data
Source in the Name text box
o Select required SQL Server
name from the Server drop-
down list
o Click the Next button
Configuring JDBC-ODBC Data Source Name
Q7M1 – SC Dudy Fathan Ali S.Kom
Specifying the connection details for a DSN
o To indicate how the SQL Server
should authenticate a login ID,
select With SQL Server
authentication.. option
o Type the username in the
Login ID textbox and the
password in the Password
textbox
o Click the Next button
Configuring JDBC-ODBC Data Source Name
Q7M1 – SC Dudy Fathan Ali S.Kom
Specifying the connection details for a DSN
o Select the name of the
database from drop-down
listbox
o Click the Next button
Configuring JDBC-ODBC Data Source Name
Q7M1 – SC Dudy Fathan Ali S.Kom
Specifying the connection details for a DSN
o Click the Finish button
Configuring JDBC-ODBC Data Source Name
Q7M1 – SC Dudy Fathan Ali S.Kom
Testing the created DSN
o To test the created DSN for the connection with database, click the Test Data Source
button
Using JDBC API
Q7M1 – SC Dudy Fathan Ali S.Kom
o The JDBC API classes and interfaces are available in the java.sql
and the javax.sql packages.
o The commonly used classes and interfaces in the JDBC API are:
o DriverManager class: Loads the driver for a database.
o Driver interface: Represents a database driver. All JDBC driver classes
must implement the Driver interface.
o Connection interface: Enables you to establish a connection between a
Java application and a database.
o Statement interface: Enables you to execute SQL statements.
o ResultSet interface: Represents the information retrieved from a
database.
o SQLException class: Provides information about the exceptions that
occur while interacting with databases.
Using JDBC API
Q7M1 – SC Dudy Fathan Ali S.Kom
o The steps to create JDBC application are:
o Load a driver
o Connect to a database
o Create and execute JDBC statements
o Handle SQL exceptions
Connecting to a Database
Q7M1 – SC Dudy Fathan Ali S.Kom
Code Example [Koneksi.java]:
Creating & Executing JDBC Statements
Q7M1 – SC Dudy Fathan Ali S.Kom
Code Example [ProductCRUD.java]:
Inserting Rows in a Table
Creating & Executing JDBC Statements
Q7M1 – SC Dudy Fathan Ali S.Kom
Querying a Table
Creating & Executing JDBC Statements
Q7M1 – SC Dudy Fathan Ali S.Kom
Updating Rows in a Table
Creating & Executing JDBC Statements
Q7M1 – SC Dudy Fathan Ali S.Kom
Deleting Rows in a Table
Querying & Modifying Data Using PreparedStatement Object
Q7M1 – SC Dudy Fathan Ali S.Kom
o The PreparedStatement interface is derived from the Statement
interface and is available in the java.sql package.
o The PreparedStatement object:
o Allows you to pass runtime parameters to the SQL statements to query
and modify the data in a table.
o Is compiled and prepared only once by JDBC. The future invocation of
the PreparedStatement object does not recompile the SQL
statements.
o Helps in reducing the load on the database server and thus improving
the performance of the application.
Querying & Modifying Data Using PreparedStatement Object
Q7M1 – SC Dudy Fathan Ali S.Kom
o Methods of the PreparedStatement Interface
o The PreparedStatement interface inherits the following
methods to execute SQL statements from the Statement
interface:
o ResultSet executeQuery(): Executes a SELECT statements and
returns the result in a ResultSet object.
o int executeUpdate(): Executes an SQL statement, INSERT,
UPDATE, or DELETE and returns the count of the rows affected.
o boolean execute(): Executes an SQL statement and returns a
boolean value.
Querying & Modifying Data Using PreparedStatement Object
Q7M1 – SC Dudy Fathan Ali S.Kom
o The prepareStatement() method of the Connection object is
used to submit parameterized query to a database.
o The SQL statement can contain ‘?’ symbol as placeholders that can
be replaced by input parameters at runtime.
o The value of each ‘?’ parameter is set by calling an appropriate
setXXX() method, where XXX is the data type of the parameter.
stat = con.prepareStatement("SELECT * FROM authors WHERE au_id = ?");
stat.setString(1,"1001");
ResultSet result=stat.executeQuery();
Querying & Modifying Data Using PreparedStatement Object
Q7M1 – SC Dudy Fathan Ali S.Kom
Retrieving Rows
Querying & Modifying Data Using PreparedStatement Object
Q7M1 – SC Dudy Fathan Ali S.Kom
Inserting Rows
Querying & Modifying Data Using PreparedStatement Object
Q7M1 – SC Dudy Fathan Ali S.Kom
Updating Rows
Querying & Modifying Data Using PreparedStatement Object
Q7M1 – SC Dudy Fathan Ali S.Kom
Deleting Rows
Q7M1 – SC Dudy Fathan Ali S.Kom
Thank You!
Dudy Fathan Ali, S.Kom
dudy.fathan@eng.ui.ac.id

More Related Content

PPT
Looping statements in Java
PPT
Server Controls of ASP.Net
PPTX
MongoDB
PDF
react redux.pdf
PPTX
SQL Basics
PPTX
Array in c#
PPTX
From a monolith to microservices + REST: The evolution of LinkedIn's architec...
PPTX
Node.js Express
Looping statements in Java
Server Controls of ASP.Net
MongoDB
react redux.pdf
SQL Basics
Array in c#
From a monolith to microservices + REST: The evolution of LinkedIn's architec...
Node.js Express

What's hot (20)

PDF
Introduction to Javascript
PPTX
Introduction to Node js
PPTX
Web developnment
PPTX
Spring boot
PPT
ADO.NET
PPT
Advanced Javascript
PPTX
Single inheritance
PPTX
C# Constructors
PDF
Java Generics - by Example
PPTX
Mongoose and MongoDB 101
PPT
Introduction to ADO.NET
PPTX
Modern JS with ES6
PPTX
Angular 9
PPT
HTML 5 Tables and Forms
PDF
Java exception handling ppt
PPTX
MongoDB presentation
PPTX
Multithreading in java
PPT
C# basics
PPTX
Understanding iptables
Introduction to Javascript
Introduction to Node js
Web developnment
Spring boot
ADO.NET
Advanced Javascript
Single inheritance
C# Constructors
Java Generics - by Example
Mongoose and MongoDB 101
Introduction to ADO.NET
Modern JS with ES6
Angular 9
HTML 5 Tables and Forms
Java exception handling ppt
MongoDB presentation
Multithreading in java
C# basics
Understanding iptables
Ad

Viewers also liked (20)

PPTX
Information System Security - Konsep Manajemen Keamanan
PPTX
Network Socket Programming with JAVA
PPTX
Information System Security - Prinsip Manajemen Keamanan
PPTX
Information System Security - Akuntabilitas dan Akses Kontrol
PPTX
Object Oriented Programming - Inheritance
PPTX
Object Oriented Programming - File Input & Output
PPTX
Object Oriented Programming - Value Types & Reference Types
PPTX
Information System Security - Kriptografi
PPTX
Object Oriented Programming - Constructors & Destructors
PPTX
Web Programming Syaria - Pengenalan Halaman Web
PPTX
Database Introduction - Akses Data dengan SQL Server
PPTX
Software Project Management - Project Management Knowledge
PPTX
Information System Security - Teknik Akses Kontrol
PPTX
Object Oriented Programming - Abstraction & Encapsulation
PPTX
Information System Security - Komponen Intranet dan Ekstranet
PPTX
Review Materi ASP.NET
PPTX
Software Project Management - Pengenalan Manajemen Proyek
DOCX
Diagram Konteks dan DFD Sistem Informasi Penjualan
PPSX
MIS BAB 10
PPTX
Software Project Management - Proses Manajemen Proyek
Information System Security - Konsep Manajemen Keamanan
Network Socket Programming with JAVA
Information System Security - Prinsip Manajemen Keamanan
Information System Security - Akuntabilitas dan Akses Kontrol
Object Oriented Programming - Inheritance
Object Oriented Programming - File Input & Output
Object Oriented Programming - Value Types & Reference Types
Information System Security - Kriptografi
Object Oriented Programming - Constructors & Destructors
Web Programming Syaria - Pengenalan Halaman Web
Database Introduction - Akses Data dengan SQL Server
Software Project Management - Project Management Knowledge
Information System Security - Teknik Akses Kontrol
Object Oriented Programming - Abstraction & Encapsulation
Information System Security - Komponen Intranet dan Ekstranet
Review Materi ASP.NET
Software Project Management - Pengenalan Manajemen Proyek
Diagram Konteks dan DFD Sistem Informasi Penjualan
MIS BAB 10
Software Project Management - Proses Manajemen Proyek
Ad

Similar to Java CRUD Mechanism with SQL Server Database (20)

PPTX
Database Connectivity with JDBC
PDF
JDBC programming
PDF
Jdbc[1]
PDF
Jdbc 1
PPT
jdbc_presentation.ppt
PPT
Chap3 3 12
PPT
Jdbc (database in java)
PDF
PPT
Jdbc oracle
PDF
Chapter6 database connectivity
PDF
4_59788783hhhhhhhhhhhhhhhhhhhhhhhhhhhhh34715564451.pdf
PDF
Introduction to JDBC and database access in web applications
PPT
JDBC.ppt
PDF
Java OOP Programming language (Part 8) - Java Database JDBC
PPTX
Jdbc Java Programming
PPTX
Jdbc presentation
PPTX
PPTX
Java Data Base Connectivity concepts.pptx
Database Connectivity with JDBC
JDBC programming
Jdbc[1]
Jdbc 1
jdbc_presentation.ppt
Chap3 3 12
Jdbc (database in java)
Jdbc oracle
Chapter6 database connectivity
4_59788783hhhhhhhhhhhhhhhhhhhhhhhhhhhhh34715564451.pdf
Introduction to JDBC and database access in web applications
JDBC.ppt
Java OOP Programming language (Part 8) - Java Database JDBC
Jdbc Java Programming
Jdbc presentation
Java Data Base Connectivity concepts.pptx

More from Dudy Ali (18)

PDF
Understanding COM+
PDF
Distributed Application Development (Introduction)
PPTX
XML Schema Part 2
PPTX
XML Schema Part 1
PPTX
Rendering XML Document
PPTX
Pengantar XML
PPTX
Pengantar XML DOM
PPTX
Pengantar ADO.NET
PPTX
XML - Displaying Data ith XSLT
PPTX
Algorithm & Data Structure - Algoritma Pengurutan
PPTX
Algorithm & Data Structure - Pengantar
PPTX
Web Programming Syaria - PHP
PPTX
System Analysis and Design - Unified Modeling Language (UML)
PPTX
System Analysis and Design - Tinjauan Umum Pengembangan Sistem
PPTX
System Analysis and Design - Introduction
PPTX
System Analysis and Design - Desain Sistem
PPTX
System Analysis and Design - Basic Characteristic of Object-Oriented Analysis
PPTX
System Analysis and Design - Analisa Sistem
Understanding COM+
Distributed Application Development (Introduction)
XML Schema Part 2
XML Schema Part 1
Rendering XML Document
Pengantar XML
Pengantar XML DOM
Pengantar ADO.NET
XML - Displaying Data ith XSLT
Algorithm & Data Structure - Algoritma Pengurutan
Algorithm & Data Structure - Pengantar
Web Programming Syaria - PHP
System Analysis and Design - Unified Modeling Language (UML)
System Analysis and Design - Tinjauan Umum Pengembangan Sistem
System Analysis and Design - Introduction
System Analysis and Design - Desain Sistem
System Analysis and Design - Basic Characteristic of Object-Oriented Analysis
System Analysis and Design - Analisa Sistem

Recently uploaded (20)

PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PDF
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
PPTX
AI IN MARKETING- PRESENTED BY ANWAR KABIR 1st June 2025.pptx
PDF
A proposed approach for plagiarism detection in Myanmar Unicode text
PDF
Comparative analysis of machine learning models for fake news detection in so...
PPTX
Build Your First AI Agent with UiPath.pptx
PDF
Flame analysis and combustion estimation using large language and vision assi...
PPTX
GROUP4NURSINGINFORMATICSREPORT-2 PRESENTATION
PDF
sustainability-14-14877-v2.pddhzftheheeeee
PPTX
The various Industrial Revolutions .pptx
PPT
Galois Field Theory of Risk: A Perspective, Protocol, and Mathematical Backgr...
PPT
Geologic Time for studying geology for geologist
PDF
Improvisation in detection of pomegranate leaf disease using transfer learni...
PDF
Architecture types and enterprise applications.pdf
PPTX
Benefits of Physical activity for teenagers.pptx
PPTX
Custom Battery Pack Design Considerations for Performance and Safety
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PDF
Credit Without Borders: AI and Financial Inclusion in Bangladesh
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
DOCX
search engine optimization ppt fir known well about this
NewMind AI Weekly Chronicles – August ’25 Week III
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
AI IN MARKETING- PRESENTED BY ANWAR KABIR 1st June 2025.pptx
A proposed approach for plagiarism detection in Myanmar Unicode text
Comparative analysis of machine learning models for fake news detection in so...
Build Your First AI Agent with UiPath.pptx
Flame analysis and combustion estimation using large language and vision assi...
GROUP4NURSINGINFORMATICSREPORT-2 PRESENTATION
sustainability-14-14877-v2.pddhzftheheeeee
The various Industrial Revolutions .pptx
Galois Field Theory of Risk: A Perspective, Protocol, and Mathematical Backgr...
Geologic Time for studying geology for geologist
Improvisation in detection of pomegranate leaf disease using transfer learni...
Architecture types and enterprise applications.pdf
Benefits of Physical activity for teenagers.pptx
Custom Battery Pack Design Considerations for Performance and Safety
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
Credit Without Borders: AI and Financial Inclusion in Bangladesh
A contest of sentiment analysis: k-nearest neighbor versus neural network
search engine optimization ppt fir known well about this

Java CRUD Mechanism with SQL Server Database

  • 1. Q7M1 – SC Dudy Fathan Ali S.Kom Java CRUD Mechanism with SQL Server Database Q7M1 Dudy Fathan Ali, S.Kom (DFA) 2017 CEP - CCIT Fakultas Teknik Universitas Indonesia
  • 2. Repository Q7M1 – SC Dudy Fathan Ali S.Kom http://bit.ly/4sc5-repo Download Presentation Slide
  • 3. Create a Database in SQL Server Q7M1 – SC Dudy Fathan Ali S.Kom To follow this lesson, you need to create a database based on the following schematic database diagram: Database name: GoShop
  • 4. Configuring JDBC-ODBC Data Source Name Q7M1 – SC Dudy Fathan Ali S.Kom You need to perform the following steps to create a Data Source Name: o Select the required driver for a DSN o Specifying the connection details for a DSN o Testing the created DSN
  • 5. Configuring JDBC-ODBC Data Source Name Q7M1 – SC Dudy Fathan Ali S.Kom Selecting the required driver for a DSN o Open Administrative Tools in Control Panel o Double-click the ODBC Data Sources Icon
  • 6. Configuring JDBC-ODBC Data Source Name Q7M1 – SC Dudy Fathan Ali S.Kom Selecting the required driver for a DSN o Select System DSN Tab o Add New System Data Sources
  • 7. Configuring JDBC-ODBC Data Source Name Q7M1 – SC Dudy Fathan Ali S.Kom Selecting the required driver for a DSN o In the Create New Data Source dialog box, select SQL Server option o Click the Finish button
  • 8. Configuring JDBC-ODBC Data Source Name Q7M1 – SC Dudy Fathan Ali S.Kom Specifying the connection details for a DSN o Type the name of the Data Source in the Name text box o Select required SQL Server name from the Server drop- down list o Click the Next button
  • 9. Configuring JDBC-ODBC Data Source Name Q7M1 – SC Dudy Fathan Ali S.Kom Specifying the connection details for a DSN o To indicate how the SQL Server should authenticate a login ID, select With SQL Server authentication.. option o Type the username in the Login ID textbox and the password in the Password textbox o Click the Next button
  • 10. Configuring JDBC-ODBC Data Source Name Q7M1 – SC Dudy Fathan Ali S.Kom Specifying the connection details for a DSN o Select the name of the database from drop-down listbox o Click the Next button
  • 11. Configuring JDBC-ODBC Data Source Name Q7M1 – SC Dudy Fathan Ali S.Kom Specifying the connection details for a DSN o Click the Finish button
  • 12. Configuring JDBC-ODBC Data Source Name Q7M1 – SC Dudy Fathan Ali S.Kom Testing the created DSN o To test the created DSN for the connection with database, click the Test Data Source button
  • 13. Using JDBC API Q7M1 – SC Dudy Fathan Ali S.Kom o The JDBC API classes and interfaces are available in the java.sql and the javax.sql packages. o The commonly used classes and interfaces in the JDBC API are: o DriverManager class: Loads the driver for a database. o Driver interface: Represents a database driver. All JDBC driver classes must implement the Driver interface. o Connection interface: Enables you to establish a connection between a Java application and a database. o Statement interface: Enables you to execute SQL statements. o ResultSet interface: Represents the information retrieved from a database. o SQLException class: Provides information about the exceptions that occur while interacting with databases.
  • 14. Using JDBC API Q7M1 – SC Dudy Fathan Ali S.Kom o The steps to create JDBC application are: o Load a driver o Connect to a database o Create and execute JDBC statements o Handle SQL exceptions
  • 15. Connecting to a Database Q7M1 – SC Dudy Fathan Ali S.Kom Code Example [Koneksi.java]:
  • 16. Creating & Executing JDBC Statements Q7M1 – SC Dudy Fathan Ali S.Kom Code Example [ProductCRUD.java]: Inserting Rows in a Table
  • 17. Creating & Executing JDBC Statements Q7M1 – SC Dudy Fathan Ali S.Kom Querying a Table
  • 18. Creating & Executing JDBC Statements Q7M1 – SC Dudy Fathan Ali S.Kom Updating Rows in a Table
  • 19. Creating & Executing JDBC Statements Q7M1 – SC Dudy Fathan Ali S.Kom Deleting Rows in a Table
  • 20. Querying & Modifying Data Using PreparedStatement Object Q7M1 – SC Dudy Fathan Ali S.Kom o The PreparedStatement interface is derived from the Statement interface and is available in the java.sql package. o The PreparedStatement object: o Allows you to pass runtime parameters to the SQL statements to query and modify the data in a table. o Is compiled and prepared only once by JDBC. The future invocation of the PreparedStatement object does not recompile the SQL statements. o Helps in reducing the load on the database server and thus improving the performance of the application.
  • 21. Querying & Modifying Data Using PreparedStatement Object Q7M1 – SC Dudy Fathan Ali S.Kom o Methods of the PreparedStatement Interface o The PreparedStatement interface inherits the following methods to execute SQL statements from the Statement interface: o ResultSet executeQuery(): Executes a SELECT statements and returns the result in a ResultSet object. o int executeUpdate(): Executes an SQL statement, INSERT, UPDATE, or DELETE and returns the count of the rows affected. o boolean execute(): Executes an SQL statement and returns a boolean value.
  • 22. Querying & Modifying Data Using PreparedStatement Object Q7M1 – SC Dudy Fathan Ali S.Kom o The prepareStatement() method of the Connection object is used to submit parameterized query to a database. o The SQL statement can contain ‘?’ symbol as placeholders that can be replaced by input parameters at runtime. o The value of each ‘?’ parameter is set by calling an appropriate setXXX() method, where XXX is the data type of the parameter. stat = con.prepareStatement("SELECT * FROM authors WHERE au_id = ?"); stat.setString(1,"1001"); ResultSet result=stat.executeQuery();
  • 23. Querying & Modifying Data Using PreparedStatement Object Q7M1 – SC Dudy Fathan Ali S.Kom Retrieving Rows
  • 24. Querying & Modifying Data Using PreparedStatement Object Q7M1 – SC Dudy Fathan Ali S.Kom Inserting Rows
  • 25. Querying & Modifying Data Using PreparedStatement Object Q7M1 – SC Dudy Fathan Ali S.Kom Updating Rows
  • 26. Querying & Modifying Data Using PreparedStatement Object Q7M1 – SC Dudy Fathan Ali S.Kom Deleting Rows
  • 27. Q7M1 – SC Dudy Fathan Ali S.Kom Thank You! Dudy Fathan Ali, S.Kom [email protected]