import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import oracle.jdbc.pool.OracleDataSource;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class for Servlet: UpdateAction
*
*/
public class UpdateAction extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
/* (non-Java-doc)
* @see javax.servlet.http.HttpServlet#HttpServlet()
*/
public UpdateAction() {
super();
}
protected void process(HttpServletRequest request, HttpServletResponse response) {
System.out.print("Update action");
try {
ServletOutputStream sos = response.getOutputStream();
response.setHeader("Cache-Control","no-store");
response.setHeader("Pragma","no-cache");
response.setContentType("text/plain");
String name = request.getParameter("uname");
String age = request.getParameter("uage");
String city = request.getParameter("ucity");
String phone = request.getParameter("uphone");
System.out.println("Name: " + name);
System.out.println("Age: " + age);
System.out.println("City: " + city);
System.out.println("Phone: " + phone);
String query ="UPDATE CRUD_DATA set age="+age+",city='"+city+"',phone="+phone+" where name='"+name+"'";
System.out.println("Query:" + query);
OracleDataSource ods = new OracleDataSource();
ods.setUser("abdel");
ods.setPassword("password");
ods.setURL("jdbc:oracle:thin:@//127.0.0.1/XE");
Connection conn = ods.getConnection();
Statement statement = conn.createStatement();
statement.executeUpdate(query);
conn.commit();
conn.close();
sos.print("{success:true}");
sos.close();
System.out.print("Done list servlet");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/* (non-Java-doc)
* @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
process(request,response);
}
/* (non-Java-doc)
* @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
process(request,response);
}
}