Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training  
 

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

Ads

 
 

Share on Google+Share on Google+

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

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

Ads
View Answers

March 21, 2012 at 12:04 PM


<[email protected] 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){}
%>

Ads