Data Base practice with IntelliJ IDEA Community Edition.
IIDEA plus Java plus MySQL plus Database Navigator plugin
“Java DB is no longer included with the recent JDK versions!”
Therefore, if you would like to practice DB with IntelliJ IDEA (Community Edition) for free (the alternative is to buy at least a month subscription for IIDEA Ultimate for 20 dollars), you would want to install and configure MySQL server and Database Navigator plugin.
Note! General environment: MS Windows.
This is our plan:
1. MySQL download, install and configure (up to Connection to database).
2. Creating ‘employees’ test database and adding records to it.
3. Executing some basic SQL commands (queries) in MySQL. (just for educational purpose)
4. install and configure (connect to MySQL) Database Navigator plugin for IIDEA.
5. Coding a console application in IIDEA to use a terminal/console window to output the results from a database.
Connecting to database
Connecting to a Database Table
6. Visualizing working (i.e. working in GUI mode) with DB in IntelliJ Community Edition with Database Navigator plugin.
7. Executing the SQL queries in IntelliJ Community Edition + Database Navigator plugin.
a) via SQL console by right-clicking “Connection” via «DB Browser» tab;
b) via creating a file with an extension .sql via “Project” tab.
MySQL has been priviously installed on my computer, that's why I didn't have to set up the passwords...
Here is the data for a data base I used:
Employees is the database.
Table Name is Workers
The columns names:
ID
First_Name
Last_Name
Job_Title
ID: 1
First Name: Helen
Last Name: James
Job Title: IT Manager
ID: 2
First Name: Eric
Last Name: Khan
Job Title: Programmer
ID: 3
First Name: Tommy
Last Name: Lee
Job Title: Systems Analyst
ID: 4
First Name: Priyanka
Last Name: Collins
Job Title: Programmer
The codes:
import java.sql.*;
public class DBConnect {
public static void main(String[] args) {
try {
String host = "jdbc:mysql://localhost:3306/employees";
String uName = "root";
String uPass = "root";
Connection con = DriverManager.getConnection(host, uName, uPass);
} catch (SQLException err) {
System.out.println(err.getMessage());
}
}
}
import java.sql.*;
public class DBConnect {
public static void main(String[] args) {
try {
String host = "jdbc:mysql://localhost:3306/employees";
String uName = "root";
String uPass = "root";
Connection con = DriverManager.getConnection(host, uName, uPass);
Statement stat = con.createStatement();
String sql = "select * from workers";
ResultSet rs = stat.executeQuery(sql);
while ( rs.next()) {
int id_col = rs.getInt("ID");
String first_name = rs.getString("First_Name");
String last_name = rs.getString("Last_Name");
String job = rs.getString("Job_Title");
String p = id_col + " " + first_name + " " + last_name + " " + job;
System.out.println(p);
}
} catch (SQLException err) {
System.out.println(err.getMessage());
}
}
}
A better name fro the folder (directory) for an .sql file is 'resources', sorry!
_____________________________________________________________________________________
____This video is made by the student of HITEK COMPUTER SCHOOL____
(1100-1200 West 73rd Avenue, Vancouver, BC V6P 6G5 CANADA)
"Hitek Computer School provides education and training in Software QA and Software Testing to prepare students for doing manual and automated testing of modern software applications according to Information Technology standards today."
https://www.hitekschool.com/static/Ou...
__________________________________________________________________________________
Help us caption & translate this video!
https://dev.amara.org/v/HRWJ/