SlideShare a Scribd company logo
1 of 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

More Related Content

Viewers also liked

Out of depth evaluation
Out of depth evaluation Out of depth evaluation
Out of depth evaluation
ladanjm
 
բարձրունքի ամփոփում
բարձրունքի ամփոփումբարձրունքի ամփոփում
բարձրունքի ամփոփում
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 III4
gavrilovic3
 
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
 
La cenicienta
La cenicientaLa cenicienta
La cenicienta
StJoesHS
 

Viewers also liked (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
 

Similar to 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.docx
JASS44
 
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
Hung-yu Lin
 
My sql with java
My sql with javaMy sql with java
My sql with java
oly07104
 
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
Steve Xu
 

Similar to 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
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
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
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
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...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

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