JDBC
The low-level API for connecting to relational databases.
Easy
try (var con = DriverManager.getConnection(url, user, pass);
var ps = con.prepareStatement("select * from readings where sensor = ?")) {
ps.setString(1, "t1");
try (var rs = ps.executeQuery()) { while (rs.next()) … }
}
Always use PreparedStatement to prevent SQL injection.
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.