package mypackage;
import java.sql.*;
public class GetMaxKic {
String kicid;
Connection con;
Statement stmt;
ResultSet set;
public GetMaxKic()
{
this.kicid=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
this.con=DriverManager.getConnection("jdbc:odbc:xkyy","sa","sa");
String sql="select max(kicid) from l_bio_brxxk";
this.stmt=this.con.createStatement();
set=stmt.executeQuery(sql);
while(set.next())
{
this.kicid=set.getString(1);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
public String getKicid()
{
return this.kicid;
}
public static void main(String[] args)
{
GetMaxKic gmk=new GetMaxKic();
System.out.println(gmk.getKicid());
System.out.println(Integer.parseInt(gmk.getKicid()));
}
出现的是这样的异常,我是用eclipse编译器.第一个打印语句没问题,到了第二个打印语句就有异常.
异常如下:
Exception in thread "main" java.lang.NumberFormatException: For input string: "9572032 "
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at mypackage.GetMaxKic.main(GetMaxKic.java:36)
import java.sql.*;
public class GetMaxKic {
String kicid;
Connection con;
Statement stmt;
ResultSet set;
public GetMaxKic()
{
this.kicid=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
this.con=DriverManager.getConnection("jdbc:odbc:xkyy","sa","sa");
String sql="select max(kicid) from l_bio_brxxk";
this.stmt=this.con.createStatement();
set=stmt.executeQuery(sql);
while(set.next())
{
this.kicid=set.getString(1);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
public String getKicid()
{
return this.kicid;
}
public static void main(String[] args)
{
GetMaxKic gmk=new GetMaxKic();
System.out.println(gmk.getKicid());
System.out.println(Integer.parseInt(gmk.getKicid()));
}
出现的是这样的异常,我是用eclipse编译器.第一个打印语句没问题,到了第二个打印语句就有异常.
异常如下:
Exception in thread "main" java.lang.NumberFormatException: For input string: "9572032 "
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at mypackage.GetMaxKic.main(GetMaxKic.java:36)
解决方案 »
- 用JAVA的MD5加密字符串,但是加密后无法进行字符串的比较
- 困扰我两天了!有关ObjectOutputStream,ObjectInputStream的问题
- JTree 的分层模糊查找
- JDK Logger 的 logging.properties问题
- JCreator中如何在builder中使得complile后,文件生成.class文件?
- 关于字符串数组
- 怎么彻底的理解父类引用指向子类对象?
- 用JAVA做的WEB服务程序的问题?!!
- 一○○分相送,请问在jbuilder7生成的程序中怎么显示中文???
- 求助 对象引用与内容
- java高手帮我看看这段代码表达的意思,赠100
- 一个关于GridBagLayout的问题(100分,决不吝啬)
数值型的, 传入空格字符串不异常就鬼了.
后面有几个空格,看到吧
System.out.println(""+Integer.parseInt(gmk.getKicid()));
里面有空格了,你如果非要这么用,就trim一下吧
s the String containing the integer representation to be parsed
radix the radix to be used while parsing s.
Returns:
the integer represented by the string argument in the specified radix.
Throws:
NumberFormatException if the String does not contain a parsable int.