JDBC / CATATAN</>↗JDBC18 Jan 2026
To use auto-generated keys in JDBC (like an AUTO_INCREMENT primary key), you need to follow a three-step process: notify the statement you want the keys, execute the update, and then retrieve them from a special ResultSet. Here is a practical example using PreparedStatement: 1. Prepare the Statement When creating your PreparedStatement, you must pass the […]
JDBC / CATATAN</>↗JDBC18 Jan 2026
To batch insert data with JDBC, you typically use the addBatch() and executeBatch() methods. This is much more efficient than executing individual INSERT statements because it reduces the number of round-trips between your application and the database. The most common and secure way to do this is with a PreparedStatement. Batch Insert with PreparedStatement Using […]
JDBC / CATATAN</>↗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 / CATATAN</>↗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 / CATATAN</>↗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 / CATATAN</>↗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 […]