来自url的Servlet getParameter,值为int

时间:2015-04-05 16:33:04

标签: java servlets

我想修改数据库中的记录 单击更新记录后 像http://localhost:8080/Phonebook/index.do?action=update&uid=7这样的网址 注意到我使用Netbeans和Tomcat来运行servlet

我想检索值uid以更新记录

代码中的

String name = request.getParameter("name");
String phone = request.getParameter("phone");
int uid = Integer.parseInt(request.getParameter("uid"));

pstmt = con.prepareStatement("UPDATE phonebook SET Name= ?, Phone=? where UID = ?");
pstmt.setString(1, name);
pstmt.setString(2, phone);
pstmt.setInt(3, uid);

我跑吧

SEVERE: Servlet.service() for servlet [JDBCServlet] in context with path [/Phonebook] threw exception
java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Integer.java:454)
at java.lang.Integer.parseInt(Integer.java:527)

我该如何解决? 感谢

0 个答案:

没有答案