java Google云平台不返回任何内容
我使用JAX RS和谷歌云平台制作了一个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;
}
我没有收到任何错误消息,只是没有返回任何内容
当我点击“员工数据库”
共 (0) 个答案