一.强制类型转换
长龙=300000; int i=(int ) long;
二、intValue (方法intI=newlong ) 30000 ).intValue );
三、将长整型转换为字符串字符串,然后跳槽到整型
长龙=300000;
inti=integer.parseint (string.value of (ll ) );
结果显示,使用queryrunner.query(connection,sql,new ScalarHandler ),args )返回int型数据时,long型建议以第3种方式迁移到int型
publicintegerselectcartscalercount (int userid ) stringSQL='selectsum ) count ) from t_cart where userId=? inti=integer.parseint (string.value of ) queryforscalar (SQL,userId ) ); 返回I; } publicobjectqueryforscalar (string SQL,Object.args )连接连接=JDBC utils.getconnection ); try { returnqueryrunner.query (连接,sql,新标量处理器),args ); }catch(exceptione ) { e.printStackTrace ); thrownewruntimeexception(e; }