Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public Response getAllStaff() {
- ArrayList<StaffInfo> staffArray = new ArrayList<>();
- Response response = null;
- String url = null;
- try {
- if (SystemProperty.environment.value() == SystemProperty.Environment.Value.Production) {
- Class.forName("com.mysql.jdbc.GoogleDriver").newInstance();
- url = "jdbc:google:mysql://{project-id}:staff-database/staffDatabase";
- }
- // Connection conn = DriverManager.getConnection(
- // "jdbc:google:mysql://your-project-id:your-instance- name/database",
- // "user", "password");
- Connection conn = DriverManager.getConnection(url, "michael", "password");
- Statement st = conn.createStatement();
- String sql = ("SELECT * FROM StaffTable;");
- ResultSet rs = st.executeQuery(sql);
- while(rs.next()){
- staffArray.add(new StaffInfo(rs.getInt(0),
- rs.getString(1),
- rs.getString(2),
- rs.getString(3),
- rs.getString(4),
- rs.getString(5)));
- }
- GenericEntity<ArrayList<StaffInfo>> entity =
- new GenericEntity<ArrayList<StaffInfo>>(staffArray) {};
- response = Response.ok(entity).build();
- // response = Response.ok(entity, MediaType)
- conn.close();
- } catch (ClassNotFoundException e) {
- // Could not find the database driver
- } catch (SQLException e) {
- // Could not connect to the database
- } catch (InstantiationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return response;
- }
Advertisement
Add Comment
Please, Sign In to add comment