response.setContentType("text/html");
PrintWriter out = response.getWriter();
Connection conn = null;
String url = "jdbc:mysql://localhost:3306/";
String dbName = "Employee";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "1234";
int Empid =Integer.parseInt(request.getParameter("Empid").toString());
String Name = request.getParameter("Name").toString();
int Age =Integer.parseInt(request.getParameter("Age").toString());
int Salary =Integer.parseInt(request.getParameter("Salary").toString());
Statement stmt;
try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url+dbName,userName,password);
System.out.println("Connected to the database");
ArrayList al=null;
ArrayList userList =new ArrayList();
String query = "insert into employee set Empid='"+Empid+"',name='"+Name+"',Age='"+Age+"',Salary='"+Salary+"'";
stmt = conn.createStatement();
int i = stmt.executeUpdate(query);
System.out.println("query" + query);
if(i>0)
{
response.sendRedirect("servletRecord");
}
conn.close();
System.out.println("Disconnected from database");
} catch (Exception e) {
e.printStackTrace();
I want to get the values and add it in a database using this program, but I don't know what error there is. What should I do next to create a corresponding webpage to enter the values and add it to the table?