Persistent Data

Persistent Data In Java and database management systems, Persistent Data refers to data that is stored in a way that it survives the program’s termination and can be retrieved in future executions. This is typically achieved using a database where data is stored in tables and can be accessed through SQL queries. In the context of JDBC (Java Database Connectivity), persistent data is the data stored and retrieved from relational databases. ...

May 8, 2025 · 2 min · Rohan

Resultset

ResultSet In JDBC, the ResultSet interface represents the result set of a query. It provides methods to read data returned by a query, typically from a SELECT statement. A ResultSet is created by executing a query using the Statement or PreparedStatement objects, and it allows navigation and extraction of data from the result. Types of ResultSet Forward-only: This is the default type, where you can only move the cursor forward through the result set. Created with: Statement statement = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); Scrollable: ...

May 8, 2025 · 2 min · Rohan

Database Connectivity Callable Statement

CallableStatement A CallableStatement is an interface in JDBC that allows you to execute stored procedures and functions in a database. Unlike a PreparedStatement, which is used for executing SQL queries, a CallableStatement can execute database stored procedures or functions that may involve complex logic and multiple SQL statements. Benefits of CallableStatement Execute Stored Procedures: Used to call stored procedures in the database, which are precompiled and can perform complex operations. Better Performance: Stored procedures are compiled once and can be reused, improving execution speed. Return Multiple Results: Callable statements can return multiple results, including output parameters. Creating and Using a CallableStatement Create a CallableStatement Use Connection.prepareCall() to create a callable statement. ...

May 8, 2025 · 2 min · Rohan

Database Connectivity Prepared Statement

Prepared Statement A PreparedStatement is an interface in JDBC that allows you to execute SQL queries more securely and efficiently. It is used to execute parameterized SQL queries, preventing SQL injection and improving performance, especially when executing the same query multiple times with different parameters. Benefits of Prepared Statements Prevents SQL Injection: Prepared statements automatically escape user input, protecting against SQL injection attacks. Efficiency: SQL queries are precompiled, making repeated executions faster. Security: No need to manually handle input sanitization. Creating and Using a Prepared Statement Create a PreparedStatement Use Connection.prepareStatement() to create a prepared statement. ...

May 8, 2025 · 2 min · Rohan

Database Connectivity

Database Connectivity In Java, JDBC (Java Database Connectivity) provides an API for connecting to relational databases, executing SQL queries, and processing results. It enables Java applications to interact with databases like MySQL, Oracle, PostgreSQL, and others. Steps to Connect to a Database Load the Database Driver You need to load the database-specific driver class using Class.forName(). Class.forName("com.mysql.cj.jdbc.Driver"); 2. **Establish a Connection** Use the `DriverManager.getConnection()` method to establish a connection. ```java Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb", "user", "password"); Create a Statement Create a Statement object to execute SQL queries. ...

May 8, 2025 · 2 min · Rohan