SlideShare uma empresa Scribd logo
1 de 10
MySQL and JDBC Tutorial
ECT 7130
Hong Cheng
Supplement on MySQL
• http://cs.armstrong.edu/liang/intro7e/suppl
ement/Supplement4bMySQL.pdf
MySQL Download and Install

• http://dev.mysql.com/downloads/mysql/5.4.htm
• When you install the software, you can set
the root password.
Starting and Stopping MySQL Server
• Starting and stopping the server
– See Item 1 in supplement

• Login
– mysql –u root –p
– Type your password

• Create an ordinary user
– See Item 3 in supplement to create a user with name
“scott” and password “tiger”
Databases in MySQL
• show databases;
• use test;
• create database javabook;
• use javabook;
Tables
create table Course (
courseId char(5),
subjectId char(4) not null,
courseNumber integer,
title varchar(50) not null,
numOfCredits integer,
primary key (courseId)
);

create table Student (
ssn char(9),
firstName varchar(25),
mi char(1),
lastName varchar(25),
birthDate date,
street varchar(25),
phone char(11),
zipCode char(5),
deptId char(4),
primary key (ssn)
);

create table Enrollment (
ssn char(9),
courseId char(5),
dateRegistered date,
grade char(1),
primary key (ssn, courseId),
foreign key (ssn) references Student (ssn),
foreign key (courseId) references Course (courseId)
);
Load from a File
• Put the above commands in a file, e.g.,
test.sql and put in D:booktest.sql.
• Then in MySQL command line window,
type: source D:booktest.sql
Insert Tuples
• insert into Course (courseId, subjectId, courseNumber,
title, numOfCredits) values ('11113', 'CSCI', '3720',
'Database Systems', 3);
• insert into Student (ssn, firstName, mi, lastName,
birthDate, street, phone, zipCode, deptId) values
('123456789', 'John', 'M', 'Smith', '1990-01-02', 'main',
'222-333-444', '61801', 'SEEM');
• insert into Enrollment (ssn, courseId, dateRegistered,
grade) values ('123456789', '11113', '2009-9-1', 'A');
• select * from Enrollment;
Set MySQL JDBC Driver
• An easy way
– Copy slidebookmysqljdbc.jar to C:Program
FilesJavajre1.6.0_03libext
– Try to run the program

• An alternative way
– In command line window
– set classpath=%classpath
%;c:slidebookmysqljdbc.jar;
– cd slidebook
– java FindGrade
Set MySQL JDBC Driver
• An easy way
– Copy slidebookmysqljdbc.jar to C:Program
FilesJavajre1.6.0_03libext
– Try to run the program

• An alternative way
– In command line window
– set classpath=%classpath
%;c:slidebookmysqljdbc.jar;
– cd slidebook
– java FindGrade

Mais conteúdo relacionado

Destaque

Out of depth evaluation
Out of depth evaluation Out of depth evaluation
Out of depth evaluation ladanjm
 
2013 10-03 3-4-природные_территории
2013 10-03 3-4-природные_территории2013 10-03 3-4-природные_территории
2013 10-03 3-4-природные_территорииIlay Evteev
 
Research for documentary
Research for documentaryResearch for documentary
Research for documentarymorgi_fearnz
 
բարձրունքի ամփոփում
բարձրունքի ամփոփումբարձրունքի ամփոփում
բարձրունքի ամփոփումsonashahbazyan13
 
Trabajo para subir a tu blog
Trabajo para subir a tu blog Trabajo para subir a tu blog
Trabajo para subir a tu blog Joze Uresti
 
Dohrana-Gavrilovic M III4
Dohrana-Gavrilovic M III4Dohrana-Gavrilovic M III4
Dohrana-Gavrilovic M III4gavrilovic3
 
Conventions of a music magazine
Conventions of a music magazine Conventions of a music magazine
Conventions of a music magazine ChloeLouiseGreen
 
shutter island product research
shutter island product research shutter island product research
shutter island product research ladanjm
 
презентация центра
презентация центрапрезентация центра
презентация центраIlay Evteev
 
La cenicienta
La cenicientaLa cenicienta
La cenicientaStJoesHS
 
Frankenstein documentary
Frankenstein documentaryFrankenstein documentary
Frankenstein documentarymorgi_fearnz
 

Destaque (13)

Out of depth evaluation
Out of depth evaluation Out of depth evaluation
Out of depth evaluation
 
2013 10-03 3-4-природные_территории
2013 10-03 3-4-природные_территории2013 10-03 3-4-природные_территории
2013 10-03 3-4-природные_территории
 
Research for documentary
Research for documentaryResearch for documentary
Research for documentary
 
բարձրունքի ամփոփում
բարձրունքի ամփոփումբարձրունքի ամփոփում
բարձրունքի ամփոփում
 
Trabajo para subir a tu blog
Trabajo para subir a tu blog Trabajo para subir a tu blog
Trabajo para subir a tu blog
 
Dohrana-Gavrilovic M III4
Dohrana-Gavrilovic M III4Dohrana-Gavrilovic M III4
Dohrana-Gavrilovic M III4
 
Conventions of a music magazine
Conventions of a music magazine Conventions of a music magazine
Conventions of a music magazine
 
shutter island product research
shutter island product research shutter island product research
shutter island product research
 
презентация центра
презентация центрапрезентация центра
презентация центра
 
La cenicienta
La cenicientaLa cenicienta
La cenicienta
 
Frankenstein documentary
Frankenstein documentaryFrankenstein documentary
Frankenstein documentary
 
Mystic rudraksh
Mystic rudrakshMystic rudraksh
Mystic rudraksh
 
Spdy protocol
Spdy protocolSpdy protocol
Spdy protocol
 

Semelhante a My sql and jdbc tutorial

Based on the materials for this week, create your own unique Datab.docx
Based on the materials for this week, create your own unique Datab.docxBased on the materials for this week, create your own unique Datab.docx
Based on the materials for this week, create your own unique Datab.docxJASS44
 
20160821 coscup-my sql57docstorelab01
20160821 coscup-my sql57docstorelab0120160821 coscup-my sql57docstorelab01
20160821 coscup-my sql57docstorelab01Ivan Ma
 
PROGRAMMING IN JAVA -unit 5 -part I
PROGRAMMING IN JAVA -unit 5 -part IPROGRAMMING IN JAVA -unit 5 -part I
PROGRAMMING IN JAVA -unit 5 -part ISivaSankari36
 
2014 database - course 3 - PHP and MySQL
2014 database - course 3 - PHP and MySQL2014 database - course 3 - PHP and MySQL
2014 database - course 3 - PHP and MySQLHung-yu Lin
 
My sql with java
My sql with javaMy sql with java
My sql with javaoly07104
 
[2015/2016] Local data storage for web-based mobile apps
[2015/2016] Local data storage for web-based mobile apps[2015/2016] Local data storage for web-based mobile apps
[2015/2016] Local data storage for web-based mobile appsIvano Malavolta
 
Sql server 2012 tutorials writing transact-sql statements
Sql server 2012 tutorials   writing transact-sql statementsSql server 2012 tutorials   writing transact-sql statements
Sql server 2012 tutorials writing transact-sql statementsSteve Xu
 
Database Programming Techniques
Database Programming TechniquesDatabase Programming Techniques
Database Programming TechniquesRaji Ghawi
 
MySQL Document Store
MySQL Document StoreMySQL Document Store
MySQL Document StoreMario Beck
 

Semelhante a My sql and jdbc tutorial (20)

MySQL JDBC Tutorial
MySQL JDBC TutorialMySQL JDBC Tutorial
MySQL JDBC Tutorial
 
SQLITE Android
SQLITE AndroidSQLITE Android
SQLITE Android
 
Based on the materials for this week, create your own unique Datab.docx
Based on the materials for this week, create your own unique Datab.docxBased on the materials for this week, create your own unique Datab.docx
Based on the materials for this week, create your own unique Datab.docx
 
20160821 coscup-my sql57docstorelab01
20160821 coscup-my sql57docstorelab0120160821 coscup-my sql57docstorelab01
20160821 coscup-my sql57docstorelab01
 
10 jdbc
10 jdbc10 jdbc
10 jdbc
 
10 jdbc
10 jdbc10 jdbc
10 jdbc
 
PROGRAMMING IN JAVA -unit 5 -part I
PROGRAMMING IN JAVA -unit 5 -part IPROGRAMMING IN JAVA -unit 5 -part I
PROGRAMMING IN JAVA -unit 5 -part I
 
MySQL with PHP
MySQL with PHPMySQL with PHP
MySQL with PHP
 
ppt
pptppt
ppt
 
2014 database - course 3 - PHP and MySQL
2014 database - course 3 - PHP and MySQL2014 database - course 3 - PHP and MySQL
2014 database - course 3 - PHP and MySQL
 
Database connectivity in python
Database connectivity in pythonDatabase connectivity in python
Database connectivity in python
 
Python with MySql.pptx
Python with MySql.pptxPython with MySql.pptx
Python with MySql.pptx
 
Advance Mobile Application Development class 01
Advance Mobile Application Development class 01Advance Mobile Application Development class 01
Advance Mobile Application Development class 01
 
My sql with java
My sql with javaMy sql with java
My sql with java
 
SQL Injection Defense in Python
SQL Injection Defense in PythonSQL Injection Defense in Python
SQL Injection Defense in Python
 
[2015/2016] Local data storage for web-based mobile apps
[2015/2016] Local data storage for web-based mobile apps[2015/2016] Local data storage for web-based mobile apps
[2015/2016] Local data storage for web-based mobile apps
 
22jdbc
22jdbc22jdbc
22jdbc
 
Sql server 2012 tutorials writing transact-sql statements
Sql server 2012 tutorials   writing transact-sql statementsSql server 2012 tutorials   writing transact-sql statements
Sql server 2012 tutorials writing transact-sql statements
 
Database Programming Techniques
Database Programming TechniquesDatabase Programming Techniques
Database Programming Techniques
 
MySQL Document Store
MySQL Document StoreMySQL Document Store
MySQL Document Store
 

Último

"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 

Último (20)

"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 

My sql and jdbc tutorial

  • 1. MySQL and JDBC Tutorial ECT 7130 Hong Cheng
  • 2. Supplement on MySQL • http://cs.armstrong.edu/liang/intro7e/suppl ement/Supplement4bMySQL.pdf
  • 3. MySQL Download and Install • http://dev.mysql.com/downloads/mysql/5.4.htm • When you install the software, you can set the root password.
  • 4. Starting and Stopping MySQL Server • Starting and stopping the server – See Item 1 in supplement • Login – mysql –u root –p – Type your password • Create an ordinary user – See Item 3 in supplement to create a user with name “scott” and password “tiger”
  • 5. Databases in MySQL • show databases; • use test; • create database javabook; • use javabook;
  • 6. Tables create table Course ( courseId char(5), subjectId char(4) not null, courseNumber integer, title varchar(50) not null, numOfCredits integer, primary key (courseId) ); create table Student ( ssn char(9), firstName varchar(25), mi char(1), lastName varchar(25), birthDate date, street varchar(25), phone char(11), zipCode char(5), deptId char(4), primary key (ssn) ); create table Enrollment ( ssn char(9), courseId char(5), dateRegistered date, grade char(1), primary key (ssn, courseId), foreign key (ssn) references Student (ssn), foreign key (courseId) references Course (courseId) );
  • 7. Load from a File • Put the above commands in a file, e.g., test.sql and put in D:booktest.sql. • Then in MySQL command line window, type: source D:booktest.sql
  • 8. Insert Tuples • insert into Course (courseId, subjectId, courseNumber, title, numOfCredits) values ('11113', 'CSCI', '3720', 'Database Systems', 3); • insert into Student (ssn, firstName, mi, lastName, birthDate, street, phone, zipCode, deptId) values ('123456789', 'John', 'M', 'Smith', '1990-01-02', 'main', '222-333-444', '61801', 'SEEM'); • insert into Enrollment (ssn, courseId, dateRegistered, grade) values ('123456789', '11113', '2009-9-1', 'A'); • select * from Enrollment;
  • 9. Set MySQL JDBC Driver • An easy way – Copy slidebookmysqljdbc.jar to C:Program FilesJavajre1.6.0_03libext – Try to run the program • An alternative way – In command line window – set classpath=%classpath %;c:slidebookmysqljdbc.jar; – cd slidebook – java FindGrade
  • 10. Set MySQL JDBC Driver • An easy way – Copy slidebookmysqljdbc.jar to C:Program FilesJavajre1.6.0_03libext – Try to run the program • An alternative way – In command line window – set classpath=%classpath %;c:slidebookmysqljdbc.jar; – cd slidebook – java FindGrade