Java 17 Recipes


CHAPTER 12 Working with Databases


Download 3.2 Mb.
Pdf ko'rish
bet215/245
Sana02.06.2024
Hajmi3.2 Mb.
#1839910
1   ...   211   212   213   214   215   216   217   218   ...   245
Bog'liq
Java 17 Recipes

CHAPTER 12
Working with Databases
Almost any nontrivial application contains a database of some sort. Some applications 
use an in-memory database, while others use a traditional relational database 
management system (RDBMS). Whatever the case, it is essential that every Java 
developer have some skills working with databases. Over the years, the Java Database 
Connectivity (JDBC) API has evolved quite a bit, and over the past couple of releases, 
there have been some major advancements.
This chapter covers the basics of using JDBC for working with databases. You learn 
how to perform all the standard database operations and some advanced techniques for 
manipulating data.
12-1. Installing MySQL
 Problem
You want to install a database on your personal computer.
 Solution
Install MySQL. Select the manual installation because it offers some benefits and more 
control. You can back up or move databases in seconds, and you can install and reinstall 
MySQL anywhere (including a USB drive).
To install MySQL, do the following.
1. Go to 
https://dev.mysql.com/downloads/mysql/
(the MySQL 
Community Server web page) and agree to the privacy policy.
2. Ensure that the selected platform is your OS (we used Windows 
OS) and click the Download button. For Windows, select the 
version without the installer —Windows (x86, 64-bit), ZIP 
Archive—under the Other Downloads section.


424
3. Log in as a user, or register, or, if you want, you can skip this step.
4. Download the version without the installer. (The latest version 
when we downloaded was mysql-8.0.27-winx64.zip; it had 
a dimension of 209 MB.) This package contains the MySQL 
database server.
5. Extract the zip file into your root folder drive. Rename the folder 
from mysql-8.0.27- winx64 to mysql.
6. Create the “data” folder. I chose in the same mysql folder, even if 
we recommend always placing the data folder on another drive. 
This prevents loss of data and allows easy reinstallation.
7. Initialize the data directory manually before MySQL can be 
started. Open a command window and type the following under 
the bin folder.
C:\mysql\bin>mysqld --console --initialize
The --console option enables writing the diagnostic output to 
console (if you omit this option, the server writes output to the 
error log in the data folder).
Listing 
12-1
 is the result shown on the console.

Download 3.2 Mb.

Do'stlaringiz bilan baham:
1   ...   211   212   213   214   215   216   217   218   ...   245




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling