我正在开发 GCM Demo 应用程序,我正在尝试将 GCM 服务器的注册 ID 存储在 mysql 数据库中。在示例中,它存储在 Datastore 的列表中。我在服务器端的 RegisterServlet 中有以下代码用于注册,但数据库中没有注册。我真的需要你的帮助!
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException {
String regId = getParameter(req, PARAMETER_REG_ID);
try {
//Load the Driver for connection
Class.forName("com.mysql.jdbc.Driver");
//Get a connection to the particular database
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/GCMFINAL", "root", "root");
PreparedStatement pstmt=con.prepareStatement("insert into GCM(ID)values("+regId +")");
pstmt.execute();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
setSuccess(resp);
}
}