Skip to content

Instantly share code, notes, and snippets.

@MarinMario
Last active July 9, 2025 12:06
Show Gist options
  • Select an option

  • Save MarinMario/c2801da781a2fd01013cb802769ab8a3 to your computer and use it in GitHub Desktop.

Select an option

Save MarinMario/c2801da781a2fd01013cb802769ab8a3 to your computer and use it in GitHub Desktop.
import java.sql.DriverManager;
import java.util.ArrayList;
import java.util.List;
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
public static void main(String[] args) {
var rezolvare = new Rezolvare();
rezolvare.run();
}
}
final class Contact {
int Cod;
String Nume;
int Telefon;
public Contact(int cod, String nume, int telefon) {
Cod = cod;
Nume = nume;
Telefon = telefon;
}
}
final class Rezolvare {
public void run() {
var a = readDb();
for (var i : a) {
System.out.println(i.Nume);
}
}
List<Contact> readDb() {
List<Contact> contacte = new ArrayList<>();
var connStr = "jdbc:sqlite:date/contacte.db";
try {
var connection = DriverManager.getConnection(connStr);
var statement = connection.createStatement();
var sql = "SELECT * FROM Contacte";
var rs = statement.executeQuery(sql);
while (rs.next()) {
var cod = rs.getInt("Cod");
var nume = rs.getString("Nume");
var telefon = rs.getInt("Telefon");
contacte.add(new Contact(cod, nume, telefon));
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return contacte;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment