b. interact with the DB
mkdir sqlusers
cat > sqlusers/UsersDB2.java << EOF
package sqlusers;
import java.sql.*;
import java.util.*;
public class UsersDB2 {
record User(String name, int mark) {}
//public static void main(String[] args) {
public static List<User> getUsers() {
Connection c=null;
try {
String path="jdbc:sqlite:users.db";
c=DriverManager.getConnection(path);
String q="select * from Users";
Statement s=c.createStatement();
ResultSet r=s.executeQuery(q);
List<User> us = new ArrayList<User>();
while (r.next()) {
us.add(new User(r.getString("name"),r.getInt("mark")));
}
//System.out.println(us);
return us;
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
try {
if (c!=null) c.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
System.out.println(UsersDB2.getUsers());
}
}
EOF
12 - 16
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented