繁体   English   中英

Google云平台未返回任何内容

[英]Google cloud platform returning no content

我使用JAX RS和Google Cloud Platform制作了REST Api,但是当我测试api时,我得到的HTTP204没有内容返回,我认为这可能与我的数据库连接有关,但是无论我如何更改,它都无法修复

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

我没有收到任何错误消息,只是没有返回任何内容

这是我在云平台sql上看到的内容 在此处输入图片说明

当我点击“员工数据库”

在此处输入图片说明

确保进行呼叫的计算机的IP地址已获得授权。 您将在Cloud SQL的“访问控制”选项卡中找到它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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