id generation

id generation

CREATE TABLE `mohan2` (
  `sno` bigint(20) NOT NULL AUTO_INCREMENT,
  `name` varchar(30) NOT NULL,
  `sal` int(30) NOT NULL,
  `eid` varchar(30) NOT NULL,
  PRIMARY KEY (`sno`,`eid`)
)

1)
<%--index.jsp--%>
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">

    <title>My JSP 'index.jsp' starting page</title>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->

  </head>

  <body>
    <form action="insert.jsp" method=post>
      <center><b>Name:</b><input type="text" name="t1"><br><br>
              <b>Salary:</b><input type="text" name="t2"><br><br>
              <input type="submit" value="Submit">
       </center>
       </form>       
  </body>
</html>

2)
<%-- insert.jsp--%>
<%@ page language="java" import="java.sql.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">

    <title>My JSP 'insert.jsp' starting page</title>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->

  </head>
  <%!
   public int Generate(String name1,int t)
{
   int len=5;
   int x=0;
  Connection conn = null;
  Statement st=null;
  String url = "jdbc:mysql://localhost:3306/";
  String dbName = "MYSQL";
  String driver = "com.mysql.jdbc.Driver";
  String userName = "root"; 
  String password = "password";
  String eid="";
  try 
  {
  Class.forName(driver).newInstance();
  conn = DriverManager.getConnection(url+dbName,userName,password);
  st=conn.createStatement();
  ResultSet rs=st.executeQuery("select max(sno) from mohan2");
  rs.next();
  int s=rs.getInt(1);
   s=s+1;
  StringBuffer sb = new StringBuffer(len);
  sb.append("P");
  len=len-1;
  String v=String.valueOf(s);
  int p=v.length();
  len=len-p;
  while(len--!=0)
    sb.append("0");
  sb.append(v);
   eid=sb.toString();
  rs.close();
  st.close();
   st=conn.createStatement();
    x=st.executeUpdate("insert into mohan2(eid,name,sal) values('"+eid+"','"+name1+"',"+t+")");  
   st.close();
   conn.close();
  }
  catch(Exception e)
  {
    e.printStackTrace();
   }
    return x;
}
   %>
   <body>
   <%
   String name1=request.getParameter("t1");
   String sal1=request.getParameter("t2");
   int t=Integer.parseInt(sal1);
   int b=Generate(name1,t);
         if(b==1)
            out.println("<h2>Record Successfully inserted</h2>");
        else
            out.println("<h2>Failed</h2>");%>
  </body>
</html>

any body want to employee id automatically generate please try this code, useful for u

thanks

View Answers

September 6, 2012 at 11:11 AM

CREATE TABLE mohan2 ( sno bigint(20) NOT NULL AUTO_INCREMENT, name varchar(30) NOT NULL, sal int(30) NOT NULL, eid varchar(30) NOT NULL, PRIMARY KEY (sno,eid) )

1)index.jsp

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">

    <title>My JSP 'index.jsp' starting page</title>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->

  </head>

  <body>
    <form action="insert.jsp" method=post>
      <center><b>Name:</b><input type="text" name="t1"><br><br>
              <b>Salary:</b><input type="text" name="t2"><br><br>
              <input type="submit" value="Submit">
       </center>
       </form>       
  </body>
</html>

2)insert.jsp

<%@ page language="java" import="java.sql.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">

    <title>My JSP 'insert.jsp' starting page</title>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->

  </head>
  <%!
   public int Generate(String name1,int t)
{
   int len=5;
   int x=0;
  Connection conn = null;
  Statement st=null;
  String url = "jdbc:mysql://localhost:3306/";
  String dbName = "MYSQL";
  String driver = "com.mysql.jdbc.Driver";
  String userName = "root"; 
  String password = "password";
  String eid="";
  try 
  {
  Class.forName(driver).newInstance();
  conn = DriverManager.getConnection(url+dbName,userName,password);
  st=conn.createStatement();
  ResultSet rs=st.executeQuery("select max(sno) from mohan2");
  rs.next();
  int s=rs.getInt(1);
   s=s+1;
  StringBuffer sb = new StringBuffer(len);
  sb.append("P");
  len=len-1;
  String v=String.valueOf(s);
  int p=v.length();
  len=len-p;
  while(len--!=0)
    sb.append("0");
  sb.append(v);
   eid=sb.toString();
  rs.close();
  st.close();
   st=conn.createStatement();
    x=st.executeUpdate("insert into mohan2(eid,name,sal) values('"+eid+"','"+name1+"',"+t+")");  
   st.close();
   conn.close();
  }
  catch(Exception e)
  {
    e.printStackTrace();
   }
    return x;
}
   %>
   <body>
   <%
   String name1=request.getParameter("t1");
   String sal1=request.getParameter("t2");
   int t=Integer.parseInt(sal1);
   int b=Generate(name1,t);
         if(b==1)
            out.println("<h2>Record Successfully inserted</h2>");
        else
            out.println("<h2>Failed</h2>");%>
  </body>
</html>









Related Tutorials/Questions & Answers:
id generation
id generation  CREATE TABLE `mohan2` ( `sno` bigint(20) NOT NULL... to employee id automatically generate please try this code, useful for u thanks ...");%> any body want to employee id automatically generate please try
Hibernate generation Id to postgreSQL
Hibernate generation Id to postgreSQL  Hi, I'm trying to implement a id generator in Hibernate, but I'm having a problem. Hibernate doesn't seems to reset the counting when the id is generated. For example: 1 - In PostgreSQL I
Advertisements
pdf generation.
pdf generation.  i want to generate the data which is stored in mysql data base in pdf format with php. how i will do
Maven Repository/Dependency: com.ariht | config-generation-maven-plugin
Maven Repository/Dependency of Group ID com.ariht and Artifact ID config-generation-maven-plugin. Latest version of com.ariht:config-generation-maven-plugin dependencies. # Version Release Date
Barcode generation
Barcode generation  hi, I am working on a project where there is a alias no. with symbology EAN-13 for generation of barcode... now i have to write the logic for one item no if their are two or more quantities it should
report generation using jsp
report generation using jsp  report generation coding using jsp
id
id  how to find date of birth and gender in id in html with the help of javascript
report generation - EJB
report generation   how to create the report in java
Table generation error - EJB
Table generation error  Hi friends I am using EJB3.0 with sun java... "CREATE TABLE BookShop (ID INTEGER NOT NULL, BOOKNAME VARCHAR(255), AUTHOR VARCHAR(255), ISBN VARCHAR(255), PRIMARY KEY (ID))": java.sql.SQLException: Table/View
Maven Repository/Dependency: org.finos.legend.engine | legend-engine-executionPlan-generation
Maven Repository/Dependency of Group ID org.finos.legend.engine and Artifact ID legend-engine-executionPlan-generation. Latest version of org.finos.legend.engine:legend-engine-executionPlan-generation dependencies
PDF Generation for unicode characters
PDF Generation for unicode characters  Hi, How a PDF file having unicode characters is generated in JSP
Maven Repository/Dependency: org.finos.legend.engine | legend-engine-language-pure-dsl-generation
Maven Repository/Dependency of Group ID org.finos.legend.engine and Artifact ID legend-engine-language-pure-dsl-generation. Latest version of org.finos.legend.engine:legend-engine-language-pure-dsl-generation dependencies
ModuleNotFoundError: No module named 'template_generation'
ModuleNotFoundError: No module named 'template_generation'  Hi, My... named 'template_generation' How to remove the ModuleNotFoundError: No module named 'template_generation' error? Thanks   Hi
Automatic primary Generation in Hibernate - Hibernate
Automatic primary Generation in Hibernate   Hi, Ow primary key is generated automatically in hibernate.give me sample code.Thank u
Play framework dynamic form generation
Play framework dynamic form generation  I want to generate dynamic forms using play framework can any one give me some idea about dynamic form generation using play framework
ModuleNotFoundError: No module named 'odoo10-addon-contract-sale-generation'
ModuleNotFoundError: No module named 'odoo10-addon-contract-sale-generation...: ModuleNotFoundError: No module named 'odoo10-addon-contract-sale-generation' How...-generation' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'ros-job_generation'
ModuleNotFoundError: No module named 'ros-job_generation'  Hi, My... named 'ros-job_generation' How to remove the ModuleNotFoundError: No module named 'ros-job_generation' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'ros-groovy-job-generation'
ModuleNotFoundError: No module named 'ros-groovy-job-generation'  Hi...: No module named 'ros-groovy-job-generation' How to remove the ModuleNotFoundError: No module named 'ros-groovy-job-generation' error? Thanks  
ModuleNotFoundError: No module named 'odoo10-addon-contract-sale-generation'
ModuleNotFoundError: No module named 'odoo10-addon-contract-sale-generation...: ModuleNotFoundError: No module named 'odoo10-addon-contract-sale-generation' How...-generation' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'random-user-generation'
ModuleNotFoundError: No module named 'random-user-generation'  Hi...: No module named 'random-user-generation' How to remove the ModuleNotFoundError: No module named 'random-user-generation' error? Thanks   Hi
ModuleNotFoundError: No module named 'ros-job_generation'
ModuleNotFoundError: No module named 'ros-job_generation'  Hi, My... named 'ros-job_generation' How to remove the ModuleNotFoundError: No module named 'ros-job_generation' error? Thanks   Hi, In your
Version of com.ariht>config-generation-maven-plugin dependency
List of Version of com.ariht>config-generation-maven-plugin dependency
graph generation from xml design file
graph generation from xml design file  how to search words in XML file with javascript. i have copied contents of XML file into word file. using searched keywords i would like to draw graph
jsp program for bill generation - JSP-Servlet
jsp program for bill generation  hi, i just want to know how i write the jsp program for generation of bill for a gas connectivity systm  Hi Friend, Please provide some information like structure of bill. Thanks
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 ADS_TO_REPLACE_1 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
generation - Maven
report generation
frame generation
JAR Generation
JAR Generation
pattern generation
report generation
report generation
report generation
<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
jsp code for date generation - JSP-Servlet
jsp code for date generation  hai i am meyis i need a jsp program code for date generation.(mssql-back end) Fields are fromdate and todate both field are datetime datatype. Button:-save,cancel,exit todate is taken from
id creation
id creation  CREATE TABLE mohan2 ( sno bigint(20) NOT NULL AUTO_INCREMENT, name varchar(30) NOT NULL, sal int(30) NOT NULL, eid varchar(30) NOT NULL, PRIMARY KEY (sno,eid) ) import java.sql.*; import
Maven Dependency config-generation-maven-plugin >> 0.9.10
You should include the dependency code given in this page to add Maven Dependency of com.ariht >> config-generation-maven-plugin version0.9.10 in your project
Maven Dependency config-generation-maven-plugin >> 0.9.12
You should include the dependency code given in this page to add Maven Dependency of com.ariht >> config-generation-maven-plugin version0.9.12 in your project
Maven Dependency config-generation-maven-plugin >> 0.9.5
You should include the dependency code given in this page to add Maven Dependency of com.ariht >> config-generation-maven-plugin version0.9.5 in your project
Maven Dependency config-generation-maven-plugin >> 0.9.7
You should include the dependency code given in this page to add Maven Dependency of com.ariht >> config-generation-maven-plugin version0.9.7 in your project
Maven Dependency config-generation-maven-plugin >> 0.9.8
You should include the dependency code given in this page to add Maven Dependency of com.ariht >> config-generation-maven-plugin version0.9.8 in your project
Maven Dependency config-generation-maven-plugin >> 0.9.11
You should include the dependency code given in this page to add Maven Dependency of com.ariht >> config-generation-maven-plugin version0.9.11 in your project
Maven Dependency config-generation-maven-plugin >> 0.9.6
You should include the dependency code given in this page to add Maven Dependency of com.ariht >> config-generation-maven-plugin version0.9.6 in your project
Maven Dependency config-generation-maven-plugin >> 0.9.9
You should include the dependency code given in this page to add Maven Dependency of com.ariht >> config-generation-maven-plugin version0.9.9 in your project
org.finos.legend.engine - legend-engine-executionPlan-generation version 4.6.1 Maven dependency. How to use legend-engine-executionPlan-generation version 4.6.1 in pom.xml?
-generation Maven dependency? How to use  org.finos.legend.engine  - Version 4.6.1 of legend-engine-executionPlan-generation in pom.xml? How to use legend-engine-executionPlan-generation version 4.6.1 in pom.xml? Learn to use
graph generation using jfreechart and retrieving values from the database
graph generation using jfreechart and retrieving values from the database  I have made a database containing 4 subject marks and name and roll... = ChartFactory .createBarChart3D( "Test", "Id", "Score", dataset
php maintain session id
php maintain session id   How to maintain session ID for a user in PHP

Ads