Introduction
Connecting your app or tool to a database is like giving it a voice — one that can ask, update, and respond to data. Whether you're building a Java school app using JDBC or using Excel to pull live data via ODBC, this tutorial will guide you through both paths clearly and practically.
Part 1: Connecting via JDBC (Java)
Step 1: Add MySQL JDBC Driver
Download from: https://dev.mysql.com/downloads/connector/j/
Include the JAR file in your project’s classpath (via IDE or build tool).
Step 2: Java Code to Connect
import java.sql.*;
public class JDBCConnection {
public static void main(String[] args) {
String url = "jdbc:mysql://localhost:3306/school";
String user = "root";
String password = "your_password";
try {
Connection conn = DriverManager.getConnection(url, user, password);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM students");
while (rs.next()) {
System.out.println(rs.getInt("roll_no") + " - " + rs.getString("name"));
}
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
1 - Aarav
2 - Diya
Part 2: Connecting via ODBC (Excel, Python, Access)
Step 1: Install ODBC Driver
- For MySQL: Install MySQL ODBC Connector from [https://dev.mysql.com/downloads/connector/odbc/](https://dev.mysql.com/downloads/connector/odbc/)
- For SQL Server: Use built-in Microsoft ODBC Driver
Step 2: Create DSN (Data Source Name)
- Go to Control Panel → Administrative Tools → ODBC Data Sources (64-bit)
- Click Add → Choose your driver (e.g., MySQL)
- Give a name (e.g.,
school_dsn), set host, port, user, password, and database
Step 3: Use DSN in Excel
- Open Excel → Data → Get Data → From Other Sources → From ODBC
- Select
school_dsn
- Choose
students table
- Use filters and transforms as needed via Power Query
Step 4: Use DSN in Python (optional)
import pyodbc
conn = pyodbc.connect("DSN=school_dsn;UID=root;PWD=your_password")
cursor = conn.cursor()
cursor.execute("SELECT name, city FROM students WHERE class = '10A'")
for row in cursor.fetchall():
print(row)
('Aarav', 'Pune')
('Diya', 'Chennai')
Summary
JDBC and ODBC open the doors to powerful SQL integration from your favorite environments — Java, Excel, Python, and more. When working with school data like student marks, attendance, or fee records, connecting properly means enabling secure, flexible access for admins, teachers, and tools alike.
What’s Next?
Up next: SQL Interview Questions — learn to handle real-world SQL problems and integrations with confidence.

About the authorSrinivas Namala
Software Engineer
Srinivas focuses on backend development, databases, systems, and the technologies used to build reliable server-side applications.
View LinkedIn profile ↗