Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9003683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:44:34+00:00 2026-06-16T00:44:34+00:00

I’m trying to make an auto increment function that each time user create table

  • 0

I’m trying to make an auto increment function that each time user create table Departmenent_id(varchar) is incremented and the id i have given A1,A2….. so what i do in my autoincrement() that i use the list of ,result getting from select Dept_id from Department and try to separate the integer part from this and adding to TreeSet collection and taking out largest element and adding to first part of String but problem i face when i take out the substring of string like 9 and parsing it into integer i m getting number format exception. Why am I getting this problem my function code is right here

    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;
}

my exception details

    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)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:44:35+00:00Added an answer on June 16, 2026 at 12:44 am

    If you are using normal jdbc, java has provided the support to read the key.

    connection = getConnection();
    String sql = "insert into table1 (col1,Rcol2) values (?, ?)";
    ps = connection.prepareStatement(sql, new String[] {"colKEY"});
    ps.setString(1, col1Val);
    ps.setString(2, col2Val);
    ps.executeUpdate();     
    
    rs = ps.getGeneratedKeys();
    if (rs.next()){
        colKey = new Integer(rs.getInt(1));
    }
    connection.commit();
    

    Hope this will help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm trying to create an if statement in PHP that prevents a single post
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I need a function that will clean a strings' special characters. I do NOT
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.