我目前正在尝试建立一个使用泽西和谷歌云平台的RESTful应用程序接口。
我已经部署了应用程序,通过这个链接我可以很好地访问它
http://2-dot-{application-id}.appspot.com/api/staff
但是,每当我尝试访问存储在那里的sql数据库时,我都会遇到问题
我可以使用sequel pro fine访问数据库,但每当我尝试编写解决方案来访问它时,我都会收到各种错误,包括:
org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor aroundWriteTo: MessageBodyWriter not found for media type=application/json, type=class java.util.ArrayList, genericType=java.util.ArrayList<com.staff.webservice.models.StaffInfo>.到目前为止,这是我访问数据库的代码,因为我出于沮丧删除了前面的代码,现在无法找回它
import java.sql.DriverManager;
import java.util.ArrayList;
import java.io.*;
import java.sql.*;
import com.google.appengine.api.utils.SystemProperty;
public class StaffDAO implements Staff{
public ArrayList<StaffInfo> getAllStaff() {
ArrayList<StaffInfo> staffArray = new ArrayList<>();
Connection connection = null;
try {
// Load the JDBC driver
String driverName = "com.mysql.jdbc.Driver"; // MySQL MM JDBC driver
Class.forName(driverName);
// Create a connection to the database
String url = "jdbc:google:mysql://{application-id}:staff-database?user={username}";
String username = "{username}";
String password = "{password}";
String databaseName = "staff-database";
String driver = "com.mysql.jdbc.GoogleDriver";
connection = DriverManager.getConnection(url, username, password);
System.out.println(connection.toString());
} catch (ClassNotFoundException e) {
// Could not find the database driver
} catch (SQLException e) {
// Could not connect to the database
}
return staffArray;
}
}如何连接到数据库并对其进行查询以检索数据并将数据发布到数据库。
发布于 2016-01-13 19:47:06
我看起来这个错误与方法的结果类型不能序列化到JSON有关。与数据库完全无关。
https://stackoverflow.com/questions/34765474
复制相似问题