Home Answers Viewqa JSP-Servlet how to auto generate number in jsp with the database connection mysql for employee number?

 
 


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

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

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









Related Pages:

Ask Questions?

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.