Created
May 27, 2022 15:48
-
-
Save Ginxo/dc2ffe5d9023ae4aa9c2e79f49f22c8d to your computer and use it in GitHub Desktop.
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 EjercicioJDBC { | |
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