
hai good morning all jsp beginner myself is sathishkumar i am developing a web application jsp. in this application i generate id card.how can u autogenerate the id in jsp.if u have sample source code available send me.post me sample source code

The given code creates an id based on the previous id of the record.
<%@page import="java.sql.*"%>
<%
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
Statement st = conn.createStatement();
ResultSet rs=st.executeQuery("SELECT id FROM user");
int id=0;
if(rs.last()){
id=rs.getInt("id")+1;
}
st.executeUpdate("insert into user(id,name,address) values("+id+",'rose','delhi')");
out.println("Data is inserted successfully");
}
catch(Exception e){}
%>
You can also generate an id of some format using the following code.
public class GenerateSerialNumber {
public static void main (String args[]){
int serialNo = 000;
for (int i=0;i<12;i++){
serialNo++;
System.out.printf("1/%03d\n", serialNo);
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.