简体   繁体   中英

Google cloud platform returning no content

Im making a REST Api using JAX RS and Google Cloud Platform, however when i test the api I get HTTP204 no content returned, I think it could be to do with my database connection but no matter what I change it doesnt fix it

@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;
}

I get no error messages just that there is no content returned

Here is what i see on cloud platform sql 在此处输入图片说明

and when i click on "staff-database"

在此处输入图片说明

Make sure the IP address of the machine from which you are making the call is authorized. You will find it in the "Access Control" tab of Cloud SQL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM