我正在研究GCM Demo应用程序,我正在尝试将注册ID从GCM服务器存储在mysql数据库中。它存储在示例中的数据存储区列表中。我在服务器端的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);
}
}
答案 0 :(得分:0)
我的猜测是你可能在这里遇到SQL语法问题:
"insert into GCM(regId)values("+regId +")"
尝试添加如下空格:
"insert into GCM (regId) values ("+regId +")"