JDBC / NOTES</>↗JDBC17 Jan 2026
To delete rows from a database using JDBC, you use the executeUpdate() method. This method is used for SQL statements that modify data (like DELETE, INSERT, or UPDATE) and returns an integer representing the number of rows affected. While you can use a simple Statement, it is highly recommended to use a PreparedStatement to prevent […]
JDBC / NOTES</>↗JDBC17 Jan 2026
To insert rows into a database using JDBC, you typically use the executeUpdate(String sql) method of a Statement or PreparedStatement object. Here are the two primary ways to do it: 1. Using PreparedStatement (Recommended) This is the standard approach because it prevents SQL Injection and is more efficient for repeated inserts. package org.kodejava.jdbc; import java.sql.Connection; […]
JDBC / NOTES</>↗JDBC16 Jan 2026
In JDBC, the executeUpdate method is used for SQL statements that modify data, such as UPDATE, INSERT, or DELETE. Unlike executeQuery, which returns a ResultSet, executeUpdate returns an int representing the number of rows affected by the operation. Here is how you can update rows using PreparedStatement (the recommended way) and Statement. 1. Using PreparedStatement […]
JDBC / NOTES</>↗JDBC16 Jan 2026
To fetch results using a ResultSet in Java JDBC, you follow a standard pattern of executing a query, iterating through the rows, and extracting data using “getter” methods. Basic Fetching Pattern Execute the Query: Use stmt.executeQuery(sql) (for Statement) or pstmt.executeQuery() (for PreparedStatement). Iterate through Rows: Use a while (rs.next()) loop. The next() method moves the […]
JDBC / NOTES</>↗JDBC15 Jan 2026
Using a CallableStatement in JDBC is the standard way to execute stored procedures. It allows you to handle input parameters (IN), output parameters (OUT), and even result sets returned by the database. Here is a guide on how to use it for different scenarios. 1. Basic Syntax The syntax for calling a stored procedure uses […]
JDBC / NOTES</>↗JDBC15 Jan 2026
Using PreparedStatement is one of the most effective ways to prevent SQL injection in Java. It works by separating the SQL query structure from the data, ensuring that user input is treated strictly as data and never as part of the executable SQL command. Here is how you use it: 1. The Key Concept: Placeholders […]