JDBC / CATATAN</>↗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 / CATATAN</>↗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 […]
JDBC / CATATAN</>↗JDBC14 Jan 2026
Executing a simple SQL query using a Statement object in JDBC follows a straightforward pattern: establish a connection, create the statement, execute the query, and process the results. Here is a clean example of how to perform a SELECT query: Simple SQL Query Example package org.kodejava.jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import […]
JDBC / CATATAN</>↗JDBC14 Jan 2026
Properly closing JDBC resources is crucial to prevent memory leaks and database connection exhaustion. In modern Java, the absolute best way to do this is by using the try-with-resources statement. The Best Practice: Try-with-Resources Introduced in Java 7, this approach automatically closes any resource that implements java.lang.AutoCloseable (which Connection, Statement, and ResultSet all do) at […]
JNDI / CATATAN</>↗JNDI13 Jan 2026
Switching from DriverManager to DataSource is a best practice in modern Java applications because it supports connection pooling, is more configurable, and decouples your code from the specific database driver implementation. While DriverManager creates a physical connection every time you call getConnection(), a DataSource (specifically a pooling one) maintains a set of open connections that […]
JDBC / CATATAN</>↗JDBC13 Jan 2026
Creating a database connection with DriverManager is the standard way to establish a session with a database in JDBC. 1. The Essential Formula To get a connection, you call DriverManager.getConnection() using a Connection URL, a username, and a password. Connection connection = DriverManager.getConnection(url, username, password); 2. Implementation Example In modern Java (JDBC 4.0+), you don’t […]