need to generate ID

need to generate ID

hai, i need to generate ID i.e when i select addemploye option and submit, it should generate a emp ID which is 1 greater than the previous highest ID value stored in database. eg: if the higest value of empID stored in database is 4, the next time after i select add employ option it should generate empID as 5 and i should continue with inserting other values like ename,ecity etc........Plz help

View Answers

July 3, 2012 at 11:53 AM

Here is a code that generates id into database. In the given code, we have fetched the last id from the database table and by adding 1, we have generated the next id and inserted into database table.

import java.sql.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class ComboBox{

    public static void main(String[] args) throws Exception{
        JFrame f=new JFrame();
        f.setLayout(null);
        JLabel lab=new JLabel("Select Name:");

        final String st[] = {"Add Employee","Edit Employee","Delete Employee","View Employee"};
        final JComboBox combo=new JComboBox(st);
        JButton b=new JButton("Submit");

        b.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent actionEvent) {
        Object obj = combo.getSelectedItem();
        String sel=obj.toString();
        System.out.println(sel);
        if(sel.equals(st[0])){
        try{
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root" );
        Statement st=conn.createStatement();
        Statement stmt=conn.createStatement();
        ResultSet rs=st.executeQuery("select * from data1");
        int id=0;
        while(rs.next()){
            id=rs.getInt("id");
        }
        System.out.println(id);
        int ide=id+1;
        stmt.executeUpdate("insert into data1(id) values("+ide+")");
        System.out.println("Inserted");
        }
        catch(Exception e){
        System.out.println(e);
        }
        }
        }
       });
       lab.setBounds(20,20,100,20);
       combo.setBounds(120,20,80,20);
       b.setBounds(220,20,80,20);
       f.add(lab);
       f.add(combo);
       f.add(b);
       f.setVisible(true);
       f.setSize(300,120);
    }
}









Related Tutorials/Questions & Answers:
need to generate ID
need to generate ID  hai, i need to generate ID i.e when i select addemploye option and submit, it should generate a emp ID which is 1 greater than the previous highest ID value stored in database. eg: if the higest value
need to generate ID
need to generate ID  hai, i need to generate ID i.e when i select addemploye option and submit, it should generate a emp ID which is 1 greater than the previous highest ID value stored in database. eg: if the higest value
Advertisements
i need the source code to generate id in jsp
i need the source code to generate id in jsp  hai,i need the source code for generate id...which is i need to generate the new id from the maximum... of generate ids each should have some range...plz give the source code in jsp with ms
generate ID
generate ID   Statement st1=con.createStatement(); String sql="insert into employee values(emp_seq.nextval,'"+ename+"','"+eadd+"','"+ephone... EID which is generated sequentially. But what i need is, the EID sequence
Generate Employee ID (SCS-0001,SCS-0002......)
Generate Employee ID (SCS-0001,SCS-0002......)  Hello everyone i am beginner in java and i am working on my major project I want to generate bill number and employee number like SCS-0001 and so on and bill number like SCS/'date
the best way to generate a universally unique object ID.
the best way to generate a universally unique object ID.  What is the best way to generate a universally unique object ID? Do I need to use an external resource like a file or database, or can I do it all in memory
Using Hibernate <generator> to generate id incrementally - Struts
Using Hibernate to generate id incrementally  Hi All, How to increment id using Hibernate ( or if any other) to generate id. I am using... to specify the class name to be used to generate the primary key for new record while
i need a program that will generate daily base log file dynamically - Log4J
i need a program that will generate daily base log file dynamically  i need a program that will generate daily base log file dynamically For example: if suppose today date is 2 sep 2009, when i execute the program it ll
MySQL Generate AlphaNumberic Id In JSP
MySQL Generate AlphaNumberic Id In JSP In this section we will discus about how to generate id in specific format in MySQL and JSP. This example explains you that how to generate alpha numeric id in MySQL and also how to fetch
need
need  i need a jsp coding based project plz help me
Generate Keys
Generate Keys  hello i need code to generate key , after that send Keys to email address user. for example if you member in your website,if member not having Secret Keys not can download files if member having secret key i
Need to expand tree by passing Id thr URL. (not by clicking manually) - Java Server Faces Questions
Need to expand tree by passing Id thr URL. (not by clicking manually)  Sub: Need to expand tree by passing Id thr URL. Hi, Here i have... and clientId in url browser and receiving in d Library.java. I need to expand
Need to expand tree by passing Id thr URL. - Java Server Faces Questions
Need to expand tree by passing Id thr URL.  Hi, Here i have... and clientId in url browser and receiving in d Library.java. I need to expand...(this); } public TreeNode getChild(Object id) { return (TreeNode
generate file
generate file  How to generate file(.doc or .xls or .txt ) with containing data in it.By clicking on a link
how to generate auto code ?
how to generate auto code ?  i wanna genrate auto code for id in core java. pls tell me code of auto genrate
generate report
generate report  hai, im learning php so pls help me .... what is a coding for generate report by month using php... wat is a code php for create calender and listing from database... pls someone help me
generate report
generate report  hai, im learning php so pls help me .... what is a coding for generate report by month using php... wat is a code php for create calender and listing from database... pls someone help me
Generate xml
Generate xml  hi can i generate xml file with xsd using JAXP in java. if possible please send java code. Thanks.   Please visit the following link: http://www.roseindia.net/xml/creating-xml-tree.shtml
id
id  how to find date of birth and gender in id in html with the help of javascript
To Generate Excel
To Generate Excel  hi First of all my application uses Struts2 with Springs and hibernate and am new to all of that and my requirement is as follows in a jsp there will be a link where if you click on that a dialog box
generate Email - JSP-Servlet
generate Email  Hi I need to generate an automated email and need to send it to the client like an confirmation email after registering to my website. I m using jsp code. Please help me out with this issue.  Hi friend
generate report in swing
generate report in swing  generate report in swing
need answer
need answer  Given a phone number, as a string, generate the lettercombinations that are possible based on the telephone keypad's number/letter relationship (ie, 1 is related to no letters, 2 is related to 'a' 'b' 'c', 3
Generate pdf file - JSP-Servlet
Generate pdf file   Hi Friends, How to generate the pdf file for the jsp page or in servets  Hi Friend, You need to download itext api. After that set the classpath and try the following code
php generate link - PHP
php generate link  How can i generate links in PHP for my photo gallery app
generate charts using JSP
generate charts using JSP  any one know coding for generate bar chart or pie chart using JSP
ModuleNotFoundError: No module named 'generate'
ModuleNotFoundError: No module named 'generate'  Hi, My Python... 'generate' How to remove the ModuleNotFoundError: No module named 'generate... to install padas library. You can install generate python with following
need project
need project  hi im new on this site so dnt knw actual procedure . but i need a project on banking system in java with sql database. which should... account view data of customer by id and name if u have other attribute which
Java program to generate the total count
Java program to generate the total count  I need a java program which would take a text file as an input and scans through it to generate the output. For Ex. : If the text file contains the following information: There is/are 3
Generate Random Numbers
Generate Random Numbers  hi,,, Please give me answer with example How do you generate random numbers within a given limit with actionscript... This function generate random numbers with in given limit
generate pdf in spring
generate pdf in spring  HOw do i generate pdf in a spring application, so that my click should query the database and a pdf should be generated and downloaded to the client side
generate pdf in spring
generate pdf in spring  HOw do i generate pdf in a spring application, so that my click should query the database and a pdf should be generated and downloaded to the client side
pdf generate from jsp
pdf generate from jsp  how do i generate a pdf using jsp that should query the data from the database and write it into a pdf and download the same
generate pdf using jsp
generate pdf using jsp  how do i generate a pdf using jsp that should query the data from the database and write it into a pdf and download the same
Need of ORM
Need of ORM  Why do you need ORM tools like hibernate
jsf: generate another panelGrid
jsf: generate another panelGrid  hello the following is my code print("code sample"); <%@ taglib uri="http://java.sun.com/jsf/html" prefix... generate another panelgrid with the same number of columns and rows (Each time I
how to generate timetable - JSP-Servlet
how to generate timetable  can i have a jsp/servlet code...... By giving starting date and ending date it will automatically generate... more courses, you need to create more tables. 1) form.jsp: From
need of code
need of code  howto convert greyscale image to binary image in java
how to generate bank account number?
how to generate bank account number?  how to generate account number?or format or rules for bank account number
Javascript generate textbox
Javascript generate textbox In this tutorial, you will learn how to generate...;script> function generate() { var no = document.getElementById("text"...;+'<input type="text" id=text'+i+'><br>\n'
need coding
need coding  sir i need code for simple bank application in jsp please send it   sir i need the coding for simple bank application in jsp.   Please visit the following link: Jsp Bank Application
to generate barcharts - Java Beginners
to generate barcharts  Please kindly suggest: to generate a bar chart which should take data from backend(JDBC),in which Y-axis should represent...) If you want to generate bar chart using JFreeChart in java, try the following
Need Suggistion
Need Suggistion  how to call a callable statement in our jSp page using Struts environment
urgent need
urgent need   Input a line. Count the number of words that start with a capital letter
Using Hibernate <generator> to generate id incrementally
Using Hibernate <generator> to generate id incrementally... to demonstrate it. You should not use this method to generate the primary key in case...;CREATE TABLE `book` (  `id` int(11) NOT NULL default '0', 
Need help with this!
Need help with this!  Can anyone please help me with this? It's suppose to write to a file student information: student name, student Id, test scores... to effectivly end the loop with out the need to break it. for(i=(0); i <
Need help with nested queries
Need help with nested queries  Hello, Table1 has "id", "votes" columns. Table2 has "id", "Name" column. I need to retrieve Name and its corresponging Votes. I tried with nested queries but its confusing. Can anyone please help
Need Project
Need Project  How to develop School management project by using Struts Framework? Please give me suggestion and sample examples for my project
need to Program
need to Program   Can any one help me on below How to insert more then one records in EXCEL Sheet using JSP
need query
need query  hi sir , i am beginner to sql.i need a query so that it can be helpful to my project. i have four tables each containing different fruits with different amounts. i need a query in such a way that when i say some

Ads