Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public ArrayList<String> getCourseStudents(String course) throws ClassNotFoundException{
- String student = null;
- Class.forName("org.sqlite.JDBC");
- String sql = null;
- Connection connection = null;
- Statement statement = null;
- ResultSet rs = null;
- ArrayList<String> retrieveStudent = new ArrayList<String>();
- try {
- // create a database connection
- connection = DriverManager.getConnection("jdbc:sqlite:sample.db");
- statement = connection.createStatement();
- statement.setQueryTimeout(30); // set timeout to 30 sec.
- rs = statement.executeQuery("SELECT DISTINCT student FROM endgrade WHERE course = '"+ course +"'");
- while(rs.next()){
- student = rs.getString("student");
- retrieveStudent.add(student);
- }
- }
- catch (SQLException e) {
- // if the error message is "out of memory",
- // it probably means no database file is found
- System.err.println(e.getMessage());
- } finally {
- try {
- if (connection != null)
- connection.close();
- } catch (SQLException e) {
- // connection close failed.
- System.err.println(e);
- }
- }
- return retrieveStudent;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement