Harendra Sahani wrote:I am using jsp to insert data into MS Access using JSP.
The same code when i used with JAVA it is giving me the desired result but not with JSP
Harendra Sahani wrote:Thats leave me no other choice than to use JSP...
<input type="SUBMIT">
</form>
</body>
</html>
SERVLET CODE
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
* @author Harendra.Sahani
*/
public class Trial extends HttpServlet {
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out =response.getWriter();
out.println(" start updation
");
OdbcConnection od = new OdbcConnection();
od.updataDB();
out.println("check if updated
");
}
}
JAVA CODE:
import java.sql.*;
public class OdbcConnection {
public String updataDB(){
Connection con = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ;
// Connect with a url string
con = DriverManager.getConnection("jdbc:odbc:Sample");
System.out.println("Connection ok.");
Statement sta =con.createStatement();
int c = sta.executeUpdate("INSERT INTO Customers"
+ " (ID, FirstName, SurName)"
+ " VALUES (1, 'Nitin', 'kanujia')");
sta.close();
con.close();
} catch (Exception e) {
System.err.println("Exception: "+e.getMessage());
}
return("You have checked my code");
}
}