Integer.parseInt出错!!!!
请问一下各位高人,使用这个的时候Integer.parseInt用不用在页面加什么包??
<%@ page contentType= "text/html; charset=gb2312 " language= "java " import= "java.sql.* "
errorPage= " " %>
<%@include file= "conn.jsp "%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN " "http://www.w3.org/TR/html4/loose.dtd ">
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<title> 无标题文档 </title>
</head>
<body>
<%
int i = Integer.parseInt(session.getAttribute( "int "));
//String content=new String(request.getParameter( "content ").getBytes( "ISO8859_1 "), "gb2312 ");
String sql= "insert into user_zc (jf) values( ' "+i+ " ') ";
stmt.executeUpdate(sql);
%>
</body>
</html>
------解决方案--------------------int i = Integer.parseInt((String)session.getAttribute( "int "));
//上面对应的地方改成这样。
session.getAttribute( "int ");//返回的是Object,把他强制转换为String,然后用Integer.parseInt(str);
使用的java.lang.Integer不用导入
------解决方案--------------------int i = Integer.parseInt(session.getAttribute( "int ").toString());
------解决方案--------------------不用,但是如果给出的参数是null或者不能正常转成int的 "4bd "这种,会抛出异常的
------解决方案--------------------首先Object obj = session.getAttribute( "int ")
然后int i = obj == null?0:Integer.parseInt(obj.toString());
------解决方案--------------------up
------解决方案--------------------int i = Integer.parseInt(session.getAttribute( "int "));中session.getAttribute( "int ")是OBJ型的.....String sql= "insert into user_zc (jf) values( ' "+i+ " ') ";中,既然I是数字,就不用加‘’了吧...
------解决方案--------------------sql语句中整形不需要加单引号
------解决方案--------------------jf既然是int的就不能强制转换成String吧