2013-02-23 58 views
0

我正在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); 

}

}

+0

謝謝你邁克布蘭特。 – 2013-02-23 00:48:30

回答

0

我的猜測是,你可能得了SQL語法問題就在這裏:

"insert into GCM(regId)values("+regId +")" 

嘗試增加的空間是這樣的:

"insert into GCM (regId) values ("+regId +")" 
+0

我會嘗試邁克 – 2013-02-23 00:51:47

+0

邁克,當我嘗試這一個時,你能想到其他任何可能性嗎? – 2013-02-23 00:58:23

+0

我試過了,但結果仍然一樣。請! – 2013-02-23 01:10:04