shweta patil
how to auto generate number in jsp with the database connection mysql for employee number?
1 Answer(s)      3 years and 5 months ago
Posted in : JSP-Servlet

how to auto generate number in jsp with the database connection mysql for employee number?

Advertisement
View Answers

March 21, 2012 at 12:04 PM


<%@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){}
%>