Nearby lessons

3 of 37

JDBC - SQL Syntax Quick Reference

📌 What You Will Learn
  • SQL aggregate functions: count, sum, avg, min, max
  • Real-time coding standards every JDBC program should follow
  • Setting up MySQL and running JDBC with it
  • Using try-with-resources to close things safely

SQL Syntax Quick Reference is a fundamental part of database programming with JDBC. This lesson explains SQL Syntax Quick Reference with complete, runnable code examples, clear step-by-step explanations, and common mistakes to avoid with exam-style MCQs at the end.

SQL Syntax Quick Reference

Before writing JDBC programs, be comfortable with basic SQL. Here is the quick reference every JDBC beginner needs:

Three quick notes: SQL keywords are not case-sensitive (select = SELECT), but string values are case-sensitive. Every statement ends with a semicolon. And in JDBC — SELECT uses executeQuery(), everything else uses executeUpdate().

Example01
JCode Cell
1CREATE DATABASE company; -- create a database
2USE company; -- select it
3 
4CREATE TABLE employee ( -- create a table
5 id INT PRIMARY KEY,
6 name VARCHAR(50),
7 salary DOUBLE,
8 hiredate DATE
9);
10 
11INSERT INTO employee VALUES (101, 'Rahul', 50000, '2024-01-15'); -- insert
12SELECT * FROM employee; -- select all
13SELECT name, salary FROM employee WHERE salary > 40000; -- with condition
14UPDATE employee SET salary = 55000 WHERE id = 101; -- update
15DELETE FROM employee WHERE id = 102; -- delete
16SELECT COUNT(*), MAX(salary), AVG(salary) FROM employee; -- aggregates
17SELECT * FROM employee ORDER BY salary DESC; -- sort
18SELECT * FROM employee WHERE name LIKE 'R%'; -- search pattern
19SELECT * FROM employee LIMIT 5; -- first 5 rows
📝 Key Takeaways
  • Aggregate functions: count, sum, avg, min, max — one summary value from many rows.
  • rs.next() then getInt(1) reads the single-row aggregate result.
  • Real-time standards: close resources, use PreparedStatement, use connection pools.
  • try-with-resources closes Connection, Statement, ResultSet automatically.
  • MySQL setup: create DB → create table → add rows → add connector JAR to classpath.

🧠 Test Your Knowledge

1 Questions
Progress: 0 / 1