我正在GCM演示應用程序上工作,我試圖從GCM服務器中存儲註冊ID到mysql數據庫中。它在示例中存儲在數據存儲的列表中。我在註冊服務器端的RegisterServlet中有以下代碼,但在數據庫中沒有註冊註冊。我真的需要你的幫助!在MySQL數據庫中保存GCM REGID
@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);
}
}
謝謝你邁克布蘭特。 – 2013-02-23 00:48:30