Created
November 11, 2025 20:19
-
-
Save renaud/ddca9221b532809d3602f89ee54b6cd4 to your computer and use it in GitHub Desktop.
Hello JDBC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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