• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

data grid with edit and delete options

 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
edit and delete option at each row of table using servlet and mysql
 
Rob Spoor
Sheriff
Pie
Posts: 20494
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Prasad Krishnegowda
Ranch Hand
Posts: 665
4
Eclipse IDE Java Spring
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would suggest to keep away from roseindia.net. It is having examples with bad practices and is poorly designed.
 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 665
4
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

You can have a look ti JQGrid http://www.trirand.com/blog/jqgrid/jqgrid.html
 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1602
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Prasad Krishnegowda
Ranch Hand
Posts: 665
4
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1602
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right, but nothing wrong it's doing the same processing.
 
Wendy Gibbons
Bartender
Posts: 1110
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1012
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1012
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1012
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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

your welcome.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic