我正在尝试创建一个自动增量功能,每次用户创建表时Departmenent_id(varchar)
都会增加并且我给 A1,A2 的 id ......所以我在我的 autoincrement() 中使用列表,结果得到从select Dept_id from Department
并尝试将整数部分从中分离并添加到TreeSet
集合中并取出最大元素并添加到字符串的第一部分但是当我取出字符串的子字符串9
并将其解析为整数时我面临的问题number format exception
。为什么我会遇到这个问题我的功能代码就在这里
private String autoIncreament() {
String id = null;
String num = null;
String result = "SELECT DEPARTMENT_ID FROM Department";
TreeSet<Integer> treeSet = new TreeSet<Integer>();
List<Map<String, Object>> result1 = getJdbcTemplate().queryForList(
result);
for (Map<String, Object> map : result1) {
id = (String) map.get("DEPARTMENT_ID");
System.out.println("id=" + id);
num = id.substring(1);
int number = Integer.parseInt(num);
treeSet.add(number);
}
Integer in = treeSet.pollLast();
int c=in.intValue();
c++;
id = id +c ;
/* System.out.println("jcak="+rowSet.getRow()); */
return id;
}
我的异常详情
19 Dec, 2012 11:25:14 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@5d764be1: startup date [Wed Dec 19 11:25:14 IST 2012]; root of context hierarchy
19 Dec, 2012 11:25:14 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [mybeans.xml]
19 Dec, 2012 11:25:14 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@7b5a6029: defining beans [dataSource,employeeDaoImpl,departmentdao]; root of factory hierarchy
19 Dec, 2012 11:25:14 AM org.springframework.jdbc.datasource.DriverManagerDataSource setDriverClassName
INFO: Loaded JDBC driver: com.mysql.jdbc.Driver
ankur=com.nousinfo.tutorial.employee.model.Department@7eb1cc87
id=9
Exception in thread "main" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at com.nousinfo.tutorial.employee.dao.impl.DepartmentDAOImpl.autoIncreament(DepartmentDAOImpl.java:113)
at com.nousinfo.tutorial.employee.dao.impl.DepartmentDAOImpl.getDepartment(DepartmentDAOImpl.java:47)
at AccessClass.main(AccessClass.java:34)