File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes data grid with edit and delete options Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "data grid with edit and delete options" Watch "data grid with edit and delete options" New topic
Author

data grid with edit and delete options

Megha Singhal
Ranch Hand

Joined: Feb 28, 2012
Posts: 182

edit and delete option at each row of table using servlet and mysql
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19653
    
  18

Please:
- EaseUp. There is no such thing as urgent around here.
- QuoteYourSources. You mention roseindia but a link would be nice.
- TellTheDetails. You haven't given us much information, so we won't really be able to help you out.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 507

I would suggest to keep away from roseindia.net. It is having examples with bad practices and is poorly designed.


Regards, Prasad
SCJP 5 (93%)
Megha Singhal
Ranch Hand

Joined: Feb 28, 2012
Posts: 182

Prasad Krishnegowda wrote:I would suggest to keep away from roseindia.net. It is having examples with bad practices and is poorly designed.


thanks for your suggestion.
my problem is this i am having servlet page with table and i want that table data to be editable when i click on edit button that is available with each row of table and also i can able to delete a particular row.
when i click on edit button it should take me to editable page where i can make changes in the data and click on save button so that data can go in database as well as the home page. also there is facility that i can add new record in that also when i click on add new details link it will take me to new page where i can add details and click on save button so that new records are added in database as well as it will reflect on home page.

for this i have to use servlet and mysql
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 507

Till now what you have done? Show us the code and other relevant things and tell what problems you are facing. As Rob already said, TellTheDetails..
J Srinivas rao
Greenhorn

Joined: Feb 25, 2011
Posts: 9
Hi

You can have a look ti JQGrid http://www.trirand.com/blog/jqgrid/jqgrid.html
Megha Singhal
Ranch Hand

Joined: Feb 28, 2012
Posts: 182

Prasad Krishnegowda wrote:Till now what you have done? Show us the code and other relevant things and tell what problems you are facing. As Rob already said, TellTheDetails..


Below is the code
"import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.sql.*;
import java.sql.*;
import java.util.*;

public class AddUser extends HttpServlet{

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException,IOException{
response.setContentType("text/html");
PrintWriter out = response.getWriter();

System.out.println("MySQL Connect Example.");
Connection conn = null;
String url = "jdbc:mysql://localhost:3306/";
String dbName = "user_register";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "root";

String username = request.getParameter("username").toString();
String first_name = request.getParameter("first_name").toString();
String last_name = request.getParameter("last_name").toString();
String city = request.getParameter("city").toString();
String state = request.getParameter("state").toString();
String country = request.getParameter("country").toString();


Statement stmt;
try {
Class.forName(driver);
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 userregister set username='"+username+"',first_name='"+first_name+"',last_name='"+last_name+"',city='"+city+"',state='"+state+"',country='"+country+"'";
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();
}
}
}
and i am getting below error

HTTP Status 405 - HTTP method GET is not supported by this URL

--------------------------------------------------------------------------------

type Status report

message HTTP method GET is not supported by this URL

description The specified HTTP method is not allowed for the requested resource (HTTP method GET is not supported by this URL).

i tried to override the get and post method but still error doesn't remove infact errors increase...

Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1449
    
    6

Megha,

The error what you are getting hasn't go much to do with you code. In your code you are writing the doPost method. But how is the servlet invoked? Do you have any form and if so, what is the method type for form submission. It's always better to override both doPost and doGet method.


Swastik
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 507

Swastik Dey wrote:It's always better to override both doPost and doGet method.

Agree
But, Having both doGet and doPost do the same thing, is not good, they both are there for different purposes..
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1449
    
    6

Right, but nothing wrong it's doing the same processing.
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

Prasad Krishnegowda wrote:I would suggest to keep away from roseindia.net. It is having examples with bad practices and is poorly designed.


can't agree more, it is very bad.

I presume you are selecting data from the database, displaying it on screen and then letting the user edit this data.

Well i would pass the ID back to the form, and incorporate that into the edit and delete buttons.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 980
    
    2
The error is because your form method is GET (i believe) and the code you have written is in doPost().
and for your problem you should add three or whatever submit buttons in your form and check for post of each submit in your servlet, and perform the operations.
like:


and to make the text boxes editable or non-editable you can use js.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 980
    
    2
or you can also do it like this
check for the values of your submit buttons in your servlet, and perform operation correspond to the value of your submit button.
i mean create submit buttons of same names, getPrameter into your servlet and check for the button value.



i do like this.
Megha Singhal
Ranch Hand

Joined: Feb 28, 2012
Posts: 182

Punit Jain wrote:or you can also do it like this
check for the values of your submit buttons in your servlet, and perform operation correspond to the value of your submit button.
i mean create submit buttons of same names, getPrameter into your servlet and check for the button value.



i do like this.


thanks to all for your suggestions i try to implement your methods..
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 980
    
    2

thanks to all for your suggestions i try to implement your methods..

your welcome.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: data grid with edit and delete options
 
Similar Threads
media player applet
WA #1.....word association
Posting to bump up my count...
Text box value is not being completely filled with request attribute
The x900 effect ?