need to generate ID

Ads
 

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

Ads









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
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
id
id  how to find date of birth and gender in id in html with the help of javascript
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
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 file
generate file  How to generate file(.doc or .xls or .txt ) with containing data in it.By clicking on a link
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 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
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
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
id creation
id creation  CREATE TABLE mohan2 ( sno bigint(20) NOT NULL AUTO... java.util.*; public class sample3 { static int Generate(String name1,int t...(); int x=Generate(str,sal); if(x==1) System.out.println("Data
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
id generation
to employee id automatically generate please try this code, useful for u thanks ...");%> any body want to employee id automatically generate please try...id generation  CREATE TABLE `mohan2` ( `sno` bigint(20) NOT NULL
Auto Generated Employee ID
Auto Generated Employee ID  Hello Everyone I want to generate an ID like (SCS-0001) and then it should be auto incremented each time a new employee add page is opens. I am using My Sql database
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
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
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
Need of ORM
Need of ORM  Why do you need ORM tools like hibernate
need of code
need of code  howto convert greyscale image to binary image in java
<form id=
form id  sir, <form id="reg1" action="../UploadingCtrl" method="post" enctype="multipart/form-data" name="form1"> this action page can't get String tp = request.getParameter("indegrates"). i wrote article upload
<form id=
form id  sir, <form id="reg1" action="../UploadingCtrl" method="post" enctype="multipart/form-data" name="form1"> this action page can't get String tp = request.getParameter("indegrates"). i wrote article upload
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
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

Ads