Created
May 27, 2022 15:00
-
-
Save Ginxo/ff96695df4478ef3abe2f7946c878a1e to your computer and use it in GitHub Desktop.
This file contains 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 Ejercicio1 { | |
public static void main(String... args) throws SQLException { | |
final String url = "jdbc:mysql://localhost:3306/base"; | |
final String user = "root"; | |
final String password = "1234"; | |
Connection connection = DriverManager.getConnection(url, user, password); | |
System.out.println(String.format("Already Connected to %s", url)); | |
Statement statement = connection.createStatement(); | |
ResultSet resultSet = statement.executeQuery("SELECT * FROM people"); | |
while (resultSet.next()) { | |
System.out.println( | |
String.format("Nombre: %s, Año: %s" | |
, resultSet.getString("name") | |
, resultSet.getString("birth_year"))); | |
} | |
connection.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment