Skip to content

Instantly share code, notes, and snippets.

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