Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JDBC need to generate ID
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


sharmila
need to generate ID
1 Answer(s)      2 years and 4 months ago
Posted in : JDBC


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


Advertisement
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
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
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
id
id  how to find date of birth and gender in id in html with the help of javascript
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 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
generate file
generate file  How to generate file(.doc or .xls or .txt ) with containing data in it.By clicking on a link
need
need  i need a jsp coding based project plz help me
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 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
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
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
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
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
total id
total id  how to print and total my id number ..for example if my id is 0123456789 the output will look like this : 0123456789 0+1+2+3+4+5+6+7+8+9=45 help me plz
Session ID
Session ID  How can I change the session ID of the page?   ...' session ID values because it is very likely to result in the loss of the session or with people acquiring other users' data. The session ID value should be managed
<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
generate report in swing
generate report in swing  generate report in swing
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
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
generate charts using JSP
generate charts using JSP  any one know coding for generate bar chart or pie chart using JSP
php generate link - PHP
php generate link  How can i generate links in PHP for my photo gallery app
Advertisements
 

 

 

DMCA.com