try { Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost/mysql", "root", "root"); PreparedStatement pst=con.prepareStatement("insert into enquiry(name,email,contact,enquiry)values(?,?,?,?)"); pst.setString(1,strName); pst.setString(2,strEmail); pst.setString(3,strContact); pst.setString(4,strEnquiry); pst.executeUpdate(); out.println("Your mail is sent"); out.println("<a href=\"index.jsp\">Click here to return to Home Page"); } catch (Exception e) { System.out.println(e); } } }