当前位置:我的异常网» Java Web开发 » 插入数据库错误
插入数据库错误
www.myexceptions.net 网友分享于:2013-08-03 浏览:6次
插入数据库异常
往mysql里面的表里插数据,表里的字段见下面定义的这一片,下面的代码是往数据库里插得jsp,问题:当我在填写所有这些字段时,没问题,数据提交了上去再数据库中也能找到;但是当我只提交部分这些字段数据的时候,比如只填写了前7个,从fax往下就没写了,然后提交,代码能走下去不报错,但是数据库里面没有刚填写的这些部分数据,调试的时候发现这些字段都能取到值,没填写的也有,为“”,在myDBbean.update(sql);这出异常了:java.sql.SQLException: Incorrect integer value: '' for column 'fax' at row 1,是说无数据不能往mysql里插吗?(mysql里所有字段都设置了默认值NULL)
String name,address,postid,sector,contact,telephone,mobile,
fax,email,funds,workers,researchers,scope,fields,products,income;
name=new String(request.getParameter("bname") .getBytes("ISO8859_1"),"utf-8");
address=new String(request.getParameter("address") .getBytes("ISO8859_1"),"utf-8");
postid=new String(request.getParameter("postid") .getBytes("ISO8859_1"),"utf-8");
sector=new String(request.getParameter("sector") .getBytes("ISO8859_1"),"utf-8");
contact=new String(request.getParameter("contact") .getBytes("ISO8859_1"),"utf-8");
telephone=new String(request.getParameter("telephone") .getBytes("ISO8859_1"),"utf-8");
mobile=new String(request.getParameter("mobile") .getBytes("ISO8859_1"),"utf-8");
fax=new String(request.getParameter("fax") .getBytes("ISO8859_1"),"utf-8");
email=new String(request.getParameter("email") .getBytes("ISO8859_1"),"utf-8");
funds=new String(request.getParameter("funds") .getBytes("ISO8859_1"),"utf-8");
workers=new String(request.getParameter("workers") .getBytes("ISO8859_1"),"utf-8");
researchers=new String(request.getParameter("researchers") .getBytes("ISO8859_1"),"utf-8");
scope=new String(request.getParameter("scope") .getBytes("ISO8859_1"),"utf-8");
fields=new String(request.getParameter("fields") .getBytes("ISO8859_1"),"utf-8");
products=new String(request.getParameter("products") .getBytes("ISO8859_1"),"utf-8");
income=new String(request.getParameter("income") .getBytes("ISO8859_1"),"utf-8");
String sql;
sql="insert into enterprise (name,address,postid,InnovationSector,contact,telephone,mobile,fax,email,funds,WorkerNum,ResearchersNum,scope,TechFields,products,income) values ('"+name+"','"+address+"','"+postid+"','"+sector+"','"+contact+"','"+telephone+"','"+mobile+"','"+fax+"','"+email+"','"+funds+"','"+workers+"','"+researchers+"','"+scope+"','"+fields+"','"+products+"','"+income+"')";
if(name.length()!=0&&address.length()!=0&&postid.length()!=0&&contact.length()!=0)
{
try
{
myDBbean.update(sql);
myDBbean.close();
out.print("");
}
catch(Exception e)
{
out.print(e);
out.print("信息错误!");
}
}
else
{
out.print("
}
%>
------解决方案--------------------
fax 是integer(整型) 型的。你给的值是 "" ,这是个字符串,类型不匹配。
文章评论