SlideShare a Scribd company logo
Java Database Connectivity 
Nangarhar University Computer Science 
faculty 
Fall semester 2014 
Waheedullah Sulaimankhail
Overview 
1. JDBC Introduction 
2. JDBC Configuration 
3. Practical Examples with JDBC
1. JDBC introduction 
 JDBC stands for Java Database 
Connectivity, which is a standard 
Java API for database-independent 
connectivity between the Java 
programming language and a wide 
range of databases. 
 The JDBC library includes APIs for each 
of the tasks commonly associated with 
database usage
How JDBC works 
1. Registering JDBC Driver 
2. Making a connection to a database 
3. Creating SQL or MySQL statements 
4. Executing that SQL or MySQL queries 
in the database 
5. Viewing & Modifying the resulting 
records
2. JDBC Configuration 
 We will use eclipse and Microsoft Sql Server 
 So please install Eclipse and Ms Sql Server
Configuration . 
 Add Sql Server Path to environment variable.
Configuration .. 
 Download JDBC driver for Ms Sqlserver 
 Download the sqljdbc_<version>_enu.exe to a 
temporary directory. 
 Run sqljdbc_<version>_enu.exe (unzip it)
Configuration … 
 Copy sqljdbc_auth.dll 
 From this folder : …Microsoft JDBC Driver 4.0 
for SQL Serversqljdbc_4.0enuauthx64 
 To C: windows / System32 folder
Add JDBC Driver for Ms Sql Server to Project 
properties in Eclipse
3. Practical Examples with JDBC 
 Setting Up JDBC Examples 
 3 important steps to set up JDBC 
1. Write the import statements 
 import java.sql.*; 
2. Register JDBC Driver 
 Class.forName("com.microsoft.sqlserver.jdbc.SQL 
ServerDriver"); 
3. Creating connection and opening it 
 Connection con = 
DriverManager.getConnection("jdbc:sqlserver://loc 
alhost:1433;databaseName=db_name;integrated 
Security=true","User","Pw");
Executing queries with JDBC 
 After jdbc is set up we need to write queries and 
execute them. 
 In sql server we create query and execute them. 
 However in JDBC we need to create a statement 
and initialize the statement with object of 
connection class. 
 And execute the query with an object of 
statement class.
Create statement and execute create 
table query 
 Statement st = con.createStatement(); 
 String query = "CREATE TABLE student " + 
"(id INTEGER not NULL, " + " name 
VARCHAR(255), " + 
" fname VARCHAR(255), " + " grade 
Varchar(255), " + 
" PRIMARY KEY ( id ))" ; 
 St.executeUpdate(query); 
 System.out.println(“New Table with name student 
is created ”);
Creating Select Query and executing 
 Statement st= con.createStatement(); 
 String query= "SELECT id, first, last, age FROM 
Employee"; 
 ….. = st.executeQuery(query); 
 executeQuery method returns a dataset so we 
need to store the outcome in a dataset 
 We will rewrite the executeQuery method as 
above 
 ResultSet rs = st.executeQuery(query); 
 Now we need to fetch the data from our result set
Fetching data from data set 
 Rs.next() // will fetch the next record (next row) 
 To get each record we will run a while loop till the 
last record is reached 
 While(rs.next()) { 
 int id = rs.getInt("id"); // this will fetch the column 
named “id” 
 // the same for all other columns which we want 
to fetch from this record 
 System.out.println(“ID :”+id); // show the record 
 }
Clearing the Environment 
 Rs.close(); 
 St.close(); 
 Con.close();
Thanks for attention 
Download these slides from : 
https://app.box.com/s/62nb671lj6vsz23ylw7v

More Related Content

What's hot

JDBC ppt
JDBC pptJDBC ppt
JDBC ppt
Rohit Jain
 
DataBase Connectivity
DataBase ConnectivityDataBase Connectivity
DataBase Connectivity
Akankshaji
 
Java DataBase Connectivity API (JDBC API)
Java DataBase Connectivity API (JDBC API)Java DataBase Connectivity API (JDBC API)
Java DataBase Connectivity API (JDBC API)
Luzan Baral
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
Vaishali Modi
 
JDBC Tutorial
JDBC TutorialJDBC Tutorial
JDBC Tutorial
Information Technology
 
Jdbc
JdbcJdbc
Jdbc
Jdbc   Jdbc
Jdbc
Ishucs
 
Jdbc
JdbcJdbc
Java Database Connectivity
Java Database ConnectivityJava Database Connectivity
Java Database Connectivity
backdoor
 
Jdbc
JdbcJdbc
JDBC
JDBCJDBC
Jdbc
JdbcJdbc
Jdbc
Ishucs
 
java jdbc connection
java jdbc connectionjava jdbc connection
java jdbc connection
Waheed Warraich
 
Overview Of JDBC
Overview Of JDBCOverview Of JDBC
Overview Of JDBC
Mindfire Solutions
 
Java database connectivity with MYSQL
Java database connectivity with MYSQLJava database connectivity with MYSQL
Java database connectivity with MYSQL
Adil Mehmoood
 
Java- JDBC- Mazenet Solution
Java- JDBC- Mazenet SolutionJava- JDBC- Mazenet Solution
Java- JDBC- Mazenet Solution
Mazenetsolution
 
Jdbc
JdbcJdbc
Database and Java Database Connectivity
Database and Java Database ConnectivityDatabase and Java Database Connectivity
Database and Java Database Connectivity
Gary Yeh
 
Jdbc in servlets
Jdbc in servletsJdbc in servlets
Jdbc in servlets
Nuha Noor
 
Jdbc
JdbcJdbc

What's hot (20)

JDBC ppt
JDBC pptJDBC ppt
JDBC ppt
 
DataBase Connectivity
DataBase ConnectivityDataBase Connectivity
DataBase Connectivity
 
Java DataBase Connectivity API (JDBC API)
Java DataBase Connectivity API (JDBC API)Java DataBase Connectivity API (JDBC API)
Java DataBase Connectivity API (JDBC API)
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
 
JDBC Tutorial
JDBC TutorialJDBC Tutorial
JDBC Tutorial
 
Jdbc
JdbcJdbc
Jdbc
 
Jdbc
Jdbc   Jdbc
Jdbc
 
Jdbc
JdbcJdbc
Jdbc
 
Java Database Connectivity
Java Database ConnectivityJava Database Connectivity
Java Database Connectivity
 
Jdbc
JdbcJdbc
Jdbc
 
JDBC
JDBCJDBC
JDBC
 
Jdbc
JdbcJdbc
Jdbc
 
java jdbc connection
java jdbc connectionjava jdbc connection
java jdbc connection
 
Overview Of JDBC
Overview Of JDBCOverview Of JDBC
Overview Of JDBC
 
Java database connectivity with MYSQL
Java database connectivity with MYSQLJava database connectivity with MYSQL
Java database connectivity with MYSQL
 
Java- JDBC- Mazenet Solution
Java- JDBC- Mazenet SolutionJava- JDBC- Mazenet Solution
Java- JDBC- Mazenet Solution
 
Jdbc
JdbcJdbc
Jdbc
 
Database and Java Database Connectivity
Database and Java Database ConnectivityDatabase and Java Database Connectivity
Database and Java Database Connectivity
 
Jdbc in servlets
Jdbc in servletsJdbc in servlets
Jdbc in servlets
 
Jdbc
JdbcJdbc
Jdbc
 

Viewers also liked

Tarjumaye jadwali-quran-karim-pdf
Tarjumaye jadwali-quran-karim-pdfTarjumaye jadwali-quran-karim-pdf
Tarjumaye jadwali-quran-karim-pdf
BU
 
Introduction to graph databases in term of neo4j
Introduction to graph databases in term of neo4jIntroduction to graph databases in term of neo4j
Introduction to graph databases in term of neo4j
Abdullah Hamidi
 
How to take control of your l ife
How to take control of your l ifeHow to take control of your l ife
How to take control of your l ife
Mashooq Jami
 
Introduction to sql_02
Introduction to sql_02Introduction to sql_02
Introduction to sql_02
Esmatullah Adel
 
E learning ict4-d_presentation
E learning ict4-d_presentationE learning ict4-d_presentation
E learning ict4-d_presentation
Faculty of Computer Science Nangarhar University
 
Web design - Working with forms in HTML
Web design - Working with forms in HTMLWeb design - Working with forms in HTML
Web design - Working with forms in HTML
Mustafa Kamel Mohammadi
 
Bitcharities Cause Presentation
Bitcharities Cause PresentationBitcharities Cause Presentation
Bitcharities Cause Presentation
Francesco Rulli
 
How to speak in public
How to speak in publicHow to speak in public
How to speak in public
Jawid Qaumi
 
Simple past
Simple pastSimple past
Simple past
Zainab Bahar Aminy
 
Computational Advertising
Computational AdvertisingComputational Advertising
Computational Advertising
AhmadShah Sultani
 
Web app development_cookies_sessions_14
Web app development_cookies_sessions_14Web app development_cookies_sessions_14
Web app development_cookies_sessions_14
Hassen Poreya
 
Web Application Security and Awareness
Web Application Security and AwarenessWeb Application Security and Awareness
Web Application Security and Awareness
Abdul Rahman Sherzad
 
Fondo gallerie storiche romane - Destinazione Donna - catalogo della mostra
Fondo gallerie storiche romane - Destinazione Donna - catalogo della mostraFondo gallerie storiche romane - Destinazione Donna - catalogo della mostra
Fondo gallerie storiche romane - Destinazione Donna - catalogo della mostra
Alessandro Califano, PhD
 
Google Search Console
Google Search ConsoleGoogle Search Console
Google Search Console
Hekmat Sarwarzada
 
Enterprise Resource Planning using Odoo/OpenERP in Afghanistan
Enterprise Resource Planning using Odoo/OpenERP in AfghanistanEnterprise Resource Planning using Odoo/OpenERP in Afghanistan
Enterprise Resource Planning using Odoo/OpenERP in Afghanistan
Farshid Ghyasi
 
Architecting for failure - Why are distributed systems hard?
Architecting for failure - Why are distributed systems hard?Architecting for failure - Why are distributed systems hard?
Architecting for failure - Why are distributed systems hard?
Markus Eisele
 
Mite Nroc Beebe Aeqa
Mite Nroc Beebe AeqaMite Nroc Beebe Aeqa
Mite Nroc Beebe Aeqa
Global Networks
 
Bootstrap day3
Bootstrap day3Bootstrap day3
Bootstrap day3
Rafi Haidari
 
Monitoring Virtualized Environments
Monitoring Virtualized EnvironmentsMonitoring Virtualized Environments
Monitoring Virtualized Environments
Ahmad Khalid Nasrat
 

Viewers also liked (20)

Tarjumaye jadwali-quran-karim-pdf
Tarjumaye jadwali-quran-karim-pdfTarjumaye jadwali-quran-karim-pdf
Tarjumaye jadwali-quran-karim-pdf
 
Introduction to graph databases in term of neo4j
Introduction to graph databases in term of neo4jIntroduction to graph databases in term of neo4j
Introduction to graph databases in term of neo4j
 
How to take control of your l ife
How to take control of your l ifeHow to take control of your l ife
How to take control of your l ife
 
Introduction to sql_02
Introduction to sql_02Introduction to sql_02
Introduction to sql_02
 
E learning ict4-d_presentation
E learning ict4-d_presentationE learning ict4-d_presentation
E learning ict4-d_presentation
 
Web design - Working with forms in HTML
Web design - Working with forms in HTMLWeb design - Working with forms in HTML
Web design - Working with forms in HTML
 
Bitcharities Cause Presentation
Bitcharities Cause PresentationBitcharities Cause Presentation
Bitcharities Cause Presentation
 
How to speak in public
How to speak in publicHow to speak in public
How to speak in public
 
MyCV
MyCVMyCV
MyCV
 
Simple past
Simple pastSimple past
Simple past
 
Computational Advertising
Computational AdvertisingComputational Advertising
Computational Advertising
 
Web app development_cookies_sessions_14
Web app development_cookies_sessions_14Web app development_cookies_sessions_14
Web app development_cookies_sessions_14
 
Web Application Security and Awareness
Web Application Security and AwarenessWeb Application Security and Awareness
Web Application Security and Awareness
 
Fondo gallerie storiche romane - Destinazione Donna - catalogo della mostra
Fondo gallerie storiche romane - Destinazione Donna - catalogo della mostraFondo gallerie storiche romane - Destinazione Donna - catalogo della mostra
Fondo gallerie storiche romane - Destinazione Donna - catalogo della mostra
 
Google Search Console
Google Search ConsoleGoogle Search Console
Google Search Console
 
Enterprise Resource Planning using Odoo/OpenERP in Afghanistan
Enterprise Resource Planning using Odoo/OpenERP in AfghanistanEnterprise Resource Planning using Odoo/OpenERP in Afghanistan
Enterprise Resource Planning using Odoo/OpenERP in Afghanistan
 
Architecting for failure - Why are distributed systems hard?
Architecting for failure - Why are distributed systems hard?Architecting for failure - Why are distributed systems hard?
Architecting for failure - Why are distributed systems hard?
 
Mite Nroc Beebe Aeqa
Mite Nroc Beebe AeqaMite Nroc Beebe Aeqa
Mite Nroc Beebe Aeqa
 
Bootstrap day3
Bootstrap day3Bootstrap day3
Bootstrap day3
 
Monitoring Virtualized Environments
Monitoring Virtualized EnvironmentsMonitoring Virtualized Environments
Monitoring Virtualized Environments
 

Similar to Lecture 1. java database connectivity

Jdbc
JdbcJdbc
jdbc_presentation.ppt
jdbc_presentation.pptjdbc_presentation.ppt
jdbc_presentation.ppt
DrMeenakshiS
 
Jdbc
JdbcJdbc
Jdbc
lathasiva
 
Lecture17
Lecture17Lecture17
Lecture17
vantinhkhuc
 
Jdbc
JdbcJdbc
Jdbc
Indu Lata
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
sandeep54552
 
Java jdbc
Java jdbcJava jdbc
Java jdbc
Arati Gadgil
 
Jdbc (database in java)
Jdbc (database in java)Jdbc (database in java)
Jdbc (database in java)
Maher Abdo
 
Jdbc tutorial
Jdbc tutorialJdbc tutorial
Jdbc tutorial
Dharma Kshetri
 
Jdbc api
Jdbc apiJdbc api
Jdbc api
kamal kotecha
 
Java JDBC
Java JDBCJava JDBC
JDBC Connecticity.ppt
JDBC Connecticity.pptJDBC Connecticity.ppt
JDBC Connecticity.ppt
Swapnil Kale
 
22jdbc
22jdbc22jdbc
22jdbc
Adil Jafri
 
Data Access with JDBC
Data Access with JDBCData Access with JDBC
Data Access with JDBC
BG Java EE Course
 
Jdbc
JdbcJdbc
Jdbc Complete Notes by Java Training Center (Som Sir)
Jdbc Complete Notes by Java Training Center (Som Sir)Jdbc Complete Notes by Java Training Center (Som Sir)
Jdbc Complete Notes by Java Training Center (Som Sir)
Som Prakash Rai
 
Jdbc sasidhar
Jdbc  sasidharJdbc  sasidhar
Jdbc sasidhar
Sasidhar Kothuru
 
Jdbc[1]
Jdbc[1]Jdbc[1]
Jdbc[1]
Fulvio Corno
 
JDBC programming
JDBC programmingJDBC programming
JDBC programming
Fulvio Corno
 
Jdbc day-1
Jdbc day-1Jdbc day-1
Jdbc day-1
Soham Sengupta
 

Similar to Lecture 1. java database connectivity (20)

Jdbc
JdbcJdbc
Jdbc
 
jdbc_presentation.ppt
jdbc_presentation.pptjdbc_presentation.ppt
jdbc_presentation.ppt
 
Jdbc
JdbcJdbc
Jdbc
 
Lecture17
Lecture17Lecture17
Lecture17
 
Jdbc
JdbcJdbc
Jdbc
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
 
Java jdbc
Java jdbcJava jdbc
Java jdbc
 
Jdbc (database in java)
Jdbc (database in java)Jdbc (database in java)
Jdbc (database in java)
 
Jdbc tutorial
Jdbc tutorialJdbc tutorial
Jdbc tutorial
 
Jdbc api
Jdbc apiJdbc api
Jdbc api
 
Java JDBC
Java JDBCJava JDBC
Java JDBC
 
JDBC Connecticity.ppt
JDBC Connecticity.pptJDBC Connecticity.ppt
JDBC Connecticity.ppt
 
22jdbc
22jdbc22jdbc
22jdbc
 
Data Access with JDBC
Data Access with JDBCData Access with JDBC
Data Access with JDBC
 
Jdbc
JdbcJdbc
Jdbc
 
Jdbc Complete Notes by Java Training Center (Som Sir)
Jdbc Complete Notes by Java Training Center (Som Sir)Jdbc Complete Notes by Java Training Center (Som Sir)
Jdbc Complete Notes by Java Training Center (Som Sir)
 
Jdbc sasidhar
Jdbc  sasidharJdbc  sasidhar
Jdbc sasidhar
 
Jdbc[1]
Jdbc[1]Jdbc[1]
Jdbc[1]
 
JDBC programming
JDBC programmingJDBC programming
JDBC programming
 
Jdbc day-1
Jdbc day-1Jdbc day-1
Jdbc day-1
 

Recently uploaded

Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 

Recently uploaded (20)

Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 

Lecture 1. java database connectivity

  • 1. Java Database Connectivity Nangarhar University Computer Science faculty Fall semester 2014 Waheedullah Sulaimankhail
  • 2. Overview 1. JDBC Introduction 2. JDBC Configuration 3. Practical Examples with JDBC
  • 3. 1. JDBC introduction  JDBC stands for Java Database Connectivity, which is a standard Java API for database-independent connectivity between the Java programming language and a wide range of databases.  The JDBC library includes APIs for each of the tasks commonly associated with database usage
  • 4. How JDBC works 1. Registering JDBC Driver 2. Making a connection to a database 3. Creating SQL or MySQL statements 4. Executing that SQL or MySQL queries in the database 5. Viewing & Modifying the resulting records
  • 5. 2. JDBC Configuration  We will use eclipse and Microsoft Sql Server  So please install Eclipse and Ms Sql Server
  • 6. Configuration .  Add Sql Server Path to environment variable.
  • 7. Configuration ..  Download JDBC driver for Ms Sqlserver  Download the sqljdbc_<version>_enu.exe to a temporary directory.  Run sqljdbc_<version>_enu.exe (unzip it)
  • 8. Configuration …  Copy sqljdbc_auth.dll  From this folder : …Microsoft JDBC Driver 4.0 for SQL Serversqljdbc_4.0enuauthx64  To C: windows / System32 folder
  • 9. Add JDBC Driver for Ms Sql Server to Project properties in Eclipse
  • 10. 3. Practical Examples with JDBC  Setting Up JDBC Examples  3 important steps to set up JDBC 1. Write the import statements  import java.sql.*; 2. Register JDBC Driver  Class.forName("com.microsoft.sqlserver.jdbc.SQL ServerDriver"); 3. Creating connection and opening it  Connection con = DriverManager.getConnection("jdbc:sqlserver://loc alhost:1433;databaseName=db_name;integrated Security=true","User","Pw");
  • 11. Executing queries with JDBC  After jdbc is set up we need to write queries and execute them.  In sql server we create query and execute them.  However in JDBC we need to create a statement and initialize the statement with object of connection class.  And execute the query with an object of statement class.
  • 12. Create statement and execute create table query  Statement st = con.createStatement();  String query = "CREATE TABLE student " + "(id INTEGER not NULL, " + " name VARCHAR(255), " + " fname VARCHAR(255), " + " grade Varchar(255), " + " PRIMARY KEY ( id ))" ;  St.executeUpdate(query);  System.out.println(“New Table with name student is created ”);
  • 13. Creating Select Query and executing  Statement st= con.createStatement();  String query= "SELECT id, first, last, age FROM Employee";  ….. = st.executeQuery(query);  executeQuery method returns a dataset so we need to store the outcome in a dataset  We will rewrite the executeQuery method as above  ResultSet rs = st.executeQuery(query);  Now we need to fetch the data from our result set
  • 14. Fetching data from data set  Rs.next() // will fetch the next record (next row)  To get each record we will run a while loop till the last record is reached  While(rs.next()) {  int id = rs.getInt("id"); // this will fetch the column named “id”  // the same for all other columns which we want to fetch from this record  System.out.println(“ID :”+id); // show the record  }
  • 15. Clearing the Environment  Rs.close();  St.close();  Con.close();
  • 16. Thanks for attention Download these slides from : https://app.box.com/s/62nb671lj6vsz23ylw7v