Skip to content

Instantly share code, notes, and snippets.

@renaud
Created November 11, 2025 20:19
Show Gist options
  • Select an option

  • Save renaud/ddca9221b532809d3602f89ee54b6cd4 to your computer and use it in GitHub Desktop.

Select an option

Save renaud/ddca9221b532809d3602f89ee54b6cd4 to your computer and use it in GitHub Desktop.
Hello JDBC
import java.sql.*;
public class Main {
public static void main(String[] args) throws SQLException {
String url = "jdbc:postgresql://localhost:5432/books";
String user = "postgres";
String password = "myverysecretpassword";
Connection conn = DriverManager.getConnection(url, user, password);
Statement stmt = conn.createStatement();
// Lire les données
ResultSet rs = stmt.executeQuery("SELECT * FROM authors");
while (rs.next()) {
System.out.println(rs.getInt("au_id") + ": " + rs.getString("au_fname"));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment