Database Connectivity & Web Technologies
Overview
Database connectivity enables applications to interact with database management systems. Modern applications require efficient and secure methods to connect to databases, whether from desktop applications, web applications, or mobile apps.
Database Connectivity Methods
1. Native SQL Connectivity
Native connectivity uses database-specific APIs and drivers provided by the database vendor. Each database has its own native connectivity method:
- Oracle: Oracle Call Interface (OCI)
- SQL Server: SQL Server Native Client
- MySQL: MySQL Native Driver
- PostgreSQL: libpq
Advantages: Optimal performance, full feature support
Disadvantages: Database-specific, code not portable
2. ODBC (Open Database Connectivity)
ODBC is a standard API for accessing database management systems. It provides a database-agnostic interface:
- Uses drivers to translate ODBC calls to database-specific calls
- Works with relational databases
- Supported on multiple platforms
- Commonly used in Windows environments
ODBC Architecture
Application
↓
ODBC Driver Manager
↓
ODBC Driver (Database-specific)
↓
Database
3. DAO (Data Access Objects)
DAO is a Microsoft technology for accessing databases, primarily used with Microsoft Access and other Microsoft databases:
- Object-oriented approach
- Works with Microsoft Jet database engine
- Good for desktop applications
4. RDO (Remote Data Objects)
RDO is a Microsoft technology for accessing remote databases:
- Designed for client/server applications
- Better performance than DAO for remote databases
- Uses ODBC underneath
5. OLE-DB
OLE-DB is a Microsoft technology that provides a unified interface for accessing data from various sources:
- Can access relational and non-relational data
- Component-based architecture
- More flexible than ODBC
- Primarily Windows-based
OLE-DB Components
- Data Consumers: Applications that consume data
- Data Providers: Components that expose data
- Service Components: Provide additional services
6. ADO.NET
ADO.NET is Microsoft's data access technology for .NET Framework applications. It provides a set of classes for data access:
ADO.NET Components
- Connection: Establishes connection to database
- Command: Executes SQL statements
- DataReader: Forward-only, read-only data access
- DataAdapter: Bridges DataSet and database
- DataSet: In-memory representation of data
using System.Data.SqlClient;
// Create connection
SqlConnection conn = new SqlConnection(
"Server=localhost;Database=MyDB;User Id=user;Password=pass;");
// Open connection
conn.Open();
// Create command
SqlCommand cmd = new SqlCommand("SELECT * FROM Customers", conn);
// Execute and read
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
Console.WriteLine(reader["CustomerName"]);
}
// Close connection
conn.Close();
7. JDBC (Java Database Connectivity)
JDBC is Java's standard API for connecting to relational databases:
- Platform-independent
- Works with any database that has a JDBC driver
- Part of Java Standard Edition
- Uses drivers to connect to different databases
JDBC Driver Types
- Type 1 (JDBC-ODBC Bridge): Translates JDBC to ODBC
- Type 2 (Native API): Uses database native API
- Type 3 (Network Protocol): Pure Java, network protocol
- Type 4 (Thin Driver): Pure Java, direct database connection
import java.sql.*;
// Load driver
Class.forName("com.mysql.jdbc.Driver");
// Create connection
Connection conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/mydb", "user", "password");
// Create statement
Statement stmt = conn.createStatement();
// Execute query
ResultSet rs = stmt.executeQuery("SELECT * FROM Customers");
while (rs.next()) {
System.out.println(rs.getString("CustomerName"));
}
// Close connection
conn.close();
Database Internet Connectivity
Web-to-Database Middleware
Middleware acts as an intermediary between web servers and databases, translating requests and responses:
- Application servers: Handle business logic and database connectivity
- API gateways: Manage API requests and database connections
- Message queues: Handle asynchronous database operations
Server-Side Extensions
Server-side extensions enable dynamic web content generation:
- PHP: Server-side scripting with database support
- ASP.NET: Microsoft's web development framework
- JSP (JavaServer Pages): Java-based server-side technology
- Python frameworks: Django, Flask with database ORMs
- Node.js: JavaScript runtime with database libraries
connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Query
$sql = "SELECT * FROM Customers";
$result = $conn->query($sql);
// Display results
while($row = $result->fetch_assoc()) {
echo $row["CustomerName"] . "
";
}
// Close connection
$conn->close();
?>
Web Server Interfaces
Different interfaces connect web servers to databases:
- CGI (Common Gateway Interface): Standard protocol for web servers
- FastCGI: Improved version of CGI
- ISAPI (Internet Server API): Microsoft IIS extension
- NSAPI (Netscape Server API): Netscape server extension
The Web Browser
Modern web browsers support various technologies for database connectivity:
- HTTP/HTTPS: Protocol for communication
- WebSockets: Full-duplex communication
- REST APIs: Representational State Transfer
- GraphQL: Query language for APIs
Client-Side Extensions
Technologies that run in the browser to interact with databases:
- JavaScript: Fetch API, XMLHttpRequest for AJAX
- WebAssembly: High-performance code in browsers
- Service Workers: Background scripts for offline functionality
- IndexedDB: Browser-based database storage
Web Application Servers
Application servers provide runtime environments for web applications:
- Apache Tomcat: Java servlet container
- Microsoft IIS: Windows web server
- Nginx: High-performance web server
- Node.js: JavaScript runtime server
- Docker containers: Containerized application deployment
Web Database Development
Modern web database development follows best practices:
Architecture Patterns
- Three-tier architecture: Presentation, Application, Database layers
- MVC (Model-View-Controller): Separates concerns
- RESTful APIs: Stateless, resource-based architecture
- Microservices: Distributed, service-oriented architecture
Security Considerations
- SQL Injection prevention: Use parameterized queries
- Authentication and authorization: Secure access control
- Encryption: HTTPS for data in transit, encryption at rest
- Input validation: Validate all user inputs
- Connection pooling: Manage database connections efficiently
Extensible Markup Language (XML)
XML (Extensible Markup Language) is used for data representation and exchange:
XML in Database Context
- Data exchange: Standard format for data transfer
- Configuration: Database and application configuration
- Web services: SOAP, REST APIs
- Document storage: Store semi-structured data
1001
John Doe
john@example.com
1002
Jane Smith
jane@example.com
Document Type Definitions (DTD)
DTD defines the structure and legal elements of an XML document:
XML Schemas
XML Schema provides more powerful validation than DTD:
- Defines data types
- More complex validation rules
- Namespace support
- Better integration with databases
Best Practices
- Use connection pooling: Reuse database connections
- Implement error handling: Handle connection and query errors gracefully
- Use parameterized queries: Prevent SQL injection
- Close connections: Always close database connections
- Use transactions: Maintain data consistency
- Implement logging: Track database operations
- Secure credentials: Never hardcode passwords
- Monitor performance: Track query performance and connection usage
Next Steps
Learn about managing database operations with Security & Administration, or explore advanced topics like Distributed Databases.