peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
Hello
i have created a webpage for a project using jsp in netbeans.
I have created a listbox. I want it to display data from database(MS-access) and I should then be able to modify data in database like I should be able to change an entire record through the listbox when i enter the id(field)
when i enter the id it should show the data of all the fields in a listbox and then i can should be able to change the entries in the database.
In this code i wish to make changes in my database through the update query through a listbox.
My question is ..how do i modify the data through a listbox or a drop down menu?(after I enter the id in mywebpage)
import java.sql.*;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
* @author sawant
*/
@WebServlet(name="FbookCategory", urlPatterns={"/FbookCategory"})
public class FbookCategory 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 processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String url = "jdbc:odbc:db10";
try {
String a,b,c,d,e,f,g,h,i ;
a=request.getParameter("BookID");
b=request.getParameter("CategoryID");
c=request.getParameter("Title");
d=request.getParameter("Author");
e=request.getParameter("Publisher");
f=request.getParameter("Edition");
g=request.getParameter("Price");
h=request.getParameter("Quantity");
i=request.getParameter("Description");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection(url);
String sqlsel = "select * from Book_Details";
String sqlins="update Book_Details set CategoryID='',Title='',Author='',Publisher='',Edition='',Price='',Quantity='',Description='' where BookID = '2204' ";
Statement st=con.createStatement();
st.executeUpdate(sqlins);
ResultSet r = st.executeQuery(sqlsel);
String col1=new String();
String col2=new String();
String col3=new String();
String col4=new String();
String col5=new String();
String col6=new String();
String col7=new String();
String col8=new String();
String col9=new String();
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet FbookCategory</title>");
out.println("</head>");
out.println("<body>");
//out.println("<h1>Servlet FbookCategory at " + request.getContextPath () + "</h1>");
while(r.next())
{
col1=r.getString(1);
col2=r.getString(2);
col3=r.getString(3);
col4=r.getString(4);
col5=r.getString(5);
col6=r.getString(6);
col7=r.getString(7);
col8=r.getString(8);
col9=r.getString(9);
out.println("<h1>"+col1 + "</h1> ");
out.println("<h1>"+col2 + "</h1> ");
out.println("<h1>"+col3 + "</h1> ");
out.println("<h1>"+col4 + "</h1> ");
out.println("<h1>"+col5 + "</h1> ");
out.println("<h1>"+col6 + "</h1> ");
out.println("<h1>"+col7 + "</h1> ");
out.println("<h1>"+col8 + "</h1> ");
out.println("<h1>"+col9 + "</h1> ");
}
out.println("</body>");
out.println("</html>");
} catch(Exception e)
{
System.out.println("Error:" +e);
}
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Returns a short description of the servlet.
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}