6 private final static String DB_URL
= "jdbc:mysql://robocomp.dyndns.org/team3";
7 private final static String DB_USER
= "team3";
8 private final static String DB_PASS
= "team3";
10 private final static String STUDENT
= "Thompson";
12 private int id_student
;
13 private RepetoireList list_repetoire
;
14 private ScalesList list_scales
;
15 private SightreadingList list_sightreading
;
19 Connection conn
= null;
22 conn
= DriverManager
.getConnection(DB_URL
, DB_USER
, DB_PASS
);
23 System
.out
.println("Database connected");
25 id_student
= get_student_id(conn
, STUDENT
);
26 list_repetoire
= get_student_repetoire(conn
, id_student
);
27 list_scales
= get_student_scales(conn
, id_student
);
28 list_sightreading
= get_student_sightreading(conn
, id_student
);
30 catch (SQLException se
) {
37 System
.out
.println("Database disconnected");
45 public String
toString()
47 StringBuilder sb
= new StringBuilder();
49 sb
.append(STUDENT
).append("\n");
51 sb
.append(list_repetoire
.get(0)).append("\n").
52 append(list_scales
.get(0)).append("\n").
53 append(list_sightreading
.get(0));
58 public static void main(String
[] args
)
60 DB002 app
= new DB002();
62 System
.out
.println(app
);
65 /* *note - in the event that there are > 1 students with the same last name,
66 * we just return the first id in the database. */
67 private int get_student_id(Connection conn
, String lname
)
74 Statement st
= conn
.createStatement();
75 st
.executeQuery("select * from student where LName=\'" + lname
+
78 ResultSet result_set
= st
.getResultSet();
79 if (!result_set
.next()) {
83 int id
= result_set
.getInt("idStudent");
87 private RepetoireList
get_student_repetoire(Connection conn
, int sid
)
94 Statement st
= conn
.createStatement();
95 st
.executeQuery("select * from repetoire where Student_idStudent=" +
98 return new RepetoireList(st
.getResultSet());
101 private ScalesList
get_student_scales(Connection conn
, int sid
)
108 Statement st
= conn
.createStatement();
109 st
.executeQuery("select * from scales where Student_idStudent=" +
112 return new ScalesList(st
.getResultSet());
115 private SightreadingList
get_student_sightreading(Connection conn
, int sid
)
122 Statement st
= conn
.createStatement();
123 st
.executeQuery("select * from sightreading where Student_idStudent=" +
126 return new SightreadingList(st
.getResultSet());