Input
Output
import java.sql.*; public class PreparedStatementExample { public static void main(String[] args) { try { Class.forName("com.mysql.cj.jdbc.Driver"); Connection con = DriverManager.getConnection( "jdbc:mysql://localhost:3306/testdb", "root", "password"); String sql = "SELECT * FROM employees WHERE id = ?"; PreparedStatement ps = con.prepareStatement(sql); ps.setInt(1, 2); // Bind value to placeholder ResultSet rs = ps.executeQuery(); while (rs.next()) { System.out.println(rs.getInt("id") + " - " + rs.getString("name")); } rs.close(); ps.close(); con.close(); } catch (Exception e) { e.printStackTrace(); } } }