| | |
Adding a deleting rows
Please support our JSP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jun 2007
Posts: 15
Reputation:
Solved Threads: 0
Hi,
I am writing a code to dynamically create a table and then add delete and modify records. The table is created from an existing database table. How ever the add and the deleting of records is not wrking. I think there is some error in the query statements. Please help. Here is my code:
#
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>BP Admin</title>
</head>
<script type="text/javascript" language="javascript">
function slideit(tid)
{
if (document.getElementById(tid).style.display=="none")
{
document.getElementById(tid).style.display="";
}
else
{
document.getElementById(tid).style.display="none";
}
}
</script>
<body>
<H3>Business Processes</H3>
<table width="100%" height="100%" >
<tr>
<td height="33%"><%
Connection conn = null;
ResultSet rs1 = null;
Statement stmt = null;
ResultSetMetaData rsmd = null;
int columns=0;
String query="select bpname from businessprocessinfo;";
Class.forName("org.postgresql.Driver");
conn = DriverManager.getConnection("jdbc:postgresql://192.168.128.150:5432/thirdeye", "postgres", "postgres");
stmt = conn.createStatement();
rs1 = stmt.executeQuery(query);
while (rs1.next())
{%>
<table width="100%">
<tr>
<th></th>
<th></th>
<th></th>
</tr>
<tr>
<td width="33%"><a href="#" id="bpname"><%= rs1.getString(1) %></a> </td>
<td width="33%"><form name="form1" >
<input type="button" name="button1" value="Modify">
</form> </td>
<td width="33%"><form name="form2" method="post" action="../src/com/wss/DeleteBP.java">
<label>
<input type="button" name="button2" value="Delete">
</label>
</form> </td>
</tr>
</table>
<BR>
<%
}
%></td>
</tr>
<tr>
<td height="23"><div align="center">
<form id="form3" name="form3" >
<label>
<input type="button" name="button3" value="Add New Business Process" onclick="javascript:slideit('collapsiblediv')"/>
</label>
</form>
</div></td>
</tr>
<tr>
<td height="33%"><div id="collapsiblediv" style="display:none"><table width="100%" border="1">
<tr><th width="33%">Name</th>
<td width="33%"><form id="form4" name="form4" method="post" action="">
<label>
<input type="text" name="textfield" />
</label>
</form>
</td>
<td width="33%"><form name="form10"><input type="button" name="button10" value="Check" onclick="" /></form>
</tr>
<tr>
<th>Description</th>
<td><form id="form5" name="form5" method="post" action="">
<label>
<input type="text" name="textfield2" />
</label>
</form>
</td>
</tr>
<tr>
<th>Add Jobs</th>
<td colspan="2"><form id="form7" name="form7" >
<input type="button" name="button12" value="Add a new Job" onclick="javascript:slideit('collapsiblediv1')" />
</form>
</td>
</tr>
<tr>
<td colspan="3"></td>
</tr>
<tr><td>
<div align="center">
<form id="form6" name="form6" method="post" action="addbp.jsp">
<label>
<div align="center">
<input type="submit" name="Submit" value="Add the new BP" onclick="alert('Do you want to save changes?')"/>
</div>
</label>
</form>
</div></td></tr>
</table></div>
</tr>
<hr />
<tr>
<td height="33%">
<div id="collapsiblediv1" style="display:none">
<table width="100%" border="1">
<tr><th width="33%">Name</th>
<td width="33%"><form id="form14" name="form14" method="post" action="">
<label>
<input name="textfield1" type="text" size="100%" />
</label>
</form>
</td>
<td width="33%"><form name="form100"><input type="button" name="button100" value="Check" onclick="" /></form>
</tr>
<tr>
<th>Description</th>
<td><form id="form15" name="form15" method="post" action="">
<label>
<input name="textfield12" type="text" size="100%" />
</label>
</form>
</td>
</tr>
<tr>
<th>Add Steps</th>
<td colspan="2"><form id="form17" name="form17" >
<div align="center">
<input type="button" name="button112" value="Add a new Step" onclick="window.open('AddnewStep.jsp','window1','width=800, height=250', resizable=1)"/>
</div>
</form>
</td>
</tr>
<tr>
<td colspan="3"><form name="form50">
<div align="center">
<input type="submit" name="button24" value="Add step to job" />
</div>
</form></td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</body>
</html>
The code above creates dynamic table.
#<%@ page import="javax.servlet.http.*" %>
<%@ page import= "java.sql.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>addbptodatabase</title>
</head>
<body>
<%
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
String query="insert into businessprocessinfo values(/"" <br>
+ "request.getParameter("textfield")");";
try
{
Class.forName("org.postgresql.Driver");
con=DriverManager.getConnection("jdbc:postgresql://192.168.128.150:5432/thirdeye","postgres","postgres");
stmt=con.createStatement();
rs=stmt.executeQuery(query);
}catch (Exception e){ }
%>
</body>
</html>
This code is to add a row
#package com.wss;
import java.sql.*;
public class DeleteBP {
public static void main(String[] args) {
System.out.println("Deleting a Row from the Database!");
Connection con = null;
Statement stmt=null;
try{
Class.forName("org.postgresql.Driver");
con=DriverManager.getConnection("jdbc:postgresql://192.168.128.150:5432/thirdeye","postgres","postgres");
stmt=con.createStatement();
String query="Delete from businessprocessinfo where bpname=("request.getParameter('bpname')"
";
int delete=stmt.executeUpdate(query);
}catch(Exception e){ }
}
}
This code is to delete a row.
Please help.
Thanks a lot in advance.
Saswati
I am writing a code to dynamically create a table and then add delete and modify records. The table is created from an existing database table. How ever the add and the deleting of records is not wrking. I think there is some error in the query statements. Please help. Here is my code:
#
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>BP Admin</title>
</head>
<script type="text/javascript" language="javascript">
function slideit(tid)
{
if (document.getElementById(tid).style.display=="none")
{
document.getElementById(tid).style.display="";
}
else
{
document.getElementById(tid).style.display="none";
}
}
</script>
<body>
<H3>Business Processes</H3>
<table width="100%" height="100%" >
<tr>
<td height="33%"><%
Connection conn = null;
ResultSet rs1 = null;
Statement stmt = null;
ResultSetMetaData rsmd = null;
int columns=0;
String query="select bpname from businessprocessinfo;";
Class.forName("org.postgresql.Driver");
conn = DriverManager.getConnection("jdbc:postgresql://192.168.128.150:5432/thirdeye", "postgres", "postgres");
stmt = conn.createStatement();
rs1 = stmt.executeQuery(query);
while (rs1.next())
{%>
<table width="100%">
<tr>
<th></th>
<th></th>
<th></th>
</tr>
<tr>
<td width="33%"><a href="#" id="bpname"><%= rs1.getString(1) %></a> </td>
<td width="33%"><form name="form1" >
<input type="button" name="button1" value="Modify">
</form> </td>
<td width="33%"><form name="form2" method="post" action="../src/com/wss/DeleteBP.java">
<label>
<input type="button" name="button2" value="Delete">
</label>
</form> </td>
</tr>
</table>
<BR>
<%
}
%></td>
</tr>
<tr>
<td height="23"><div align="center">
<form id="form3" name="form3" >
<label>
<input type="button" name="button3" value="Add New Business Process" onclick="javascript:slideit('collapsiblediv')"/>
</label>
</form>
</div></td>
</tr>
<tr>
<td height="33%"><div id="collapsiblediv" style="display:none"><table width="100%" border="1">
<tr><th width="33%">Name</th>
<td width="33%"><form id="form4" name="form4" method="post" action="">
<label>
<input type="text" name="textfield" />
</label>
</form>
</td>
<td width="33%"><form name="form10"><input type="button" name="button10" value="Check" onclick="" /></form>
</tr>
<tr>
<th>Description</th>
<td><form id="form5" name="form5" method="post" action="">
<label>
<input type="text" name="textfield2" />
</label>
</form>
</td>
</tr>
<tr>
<th>Add Jobs</th>
<td colspan="2"><form id="form7" name="form7" >
<input type="button" name="button12" value="Add a new Job" onclick="javascript:slideit('collapsiblediv1')" />
</form>
</td>
</tr>
<tr>
<td colspan="3"></td>
</tr>
<tr><td>
<div align="center">
<form id="form6" name="form6" method="post" action="addbp.jsp">
<label>
<div align="center">
<input type="submit" name="Submit" value="Add the new BP" onclick="alert('Do you want to save changes?')"/>
</div>
</label>
</form>
</div></td></tr>
</table></div>
</tr>
<hr />
<tr>
<td height="33%">
<div id="collapsiblediv1" style="display:none">
<table width="100%" border="1">
<tr><th width="33%">Name</th>
<td width="33%"><form id="form14" name="form14" method="post" action="">
<label>
<input name="textfield1" type="text" size="100%" />
</label>
</form>
</td>
<td width="33%"><form name="form100"><input type="button" name="button100" value="Check" onclick="" /></form>
</tr>
<tr>
<th>Description</th>
<td><form id="form15" name="form15" method="post" action="">
<label>
<input name="textfield12" type="text" size="100%" />
</label>
</form>
</td>
</tr>
<tr>
<th>Add Steps</th>
<td colspan="2"><form id="form17" name="form17" >
<div align="center">
<input type="button" name="button112" value="Add a new Step" onclick="window.open('AddnewStep.jsp','window1','width=800, height=250', resizable=1)"/>
</div>
</form>
</td>
</tr>
<tr>
<td colspan="3"><form name="form50">
<div align="center">
<input type="submit" name="button24" value="Add step to job" />
</div>
</form></td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</body>
</html>
The code above creates dynamic table.
#<%@ page import="javax.servlet.http.*" %>
<%@ page import= "java.sql.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>addbptodatabase</title>
</head>
<body>
<%
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
String query="insert into businessprocessinfo values(/"" <br>
+ "request.getParameter("textfield")");";
try
{
Class.forName("org.postgresql.Driver");
con=DriverManager.getConnection("jdbc:postgresql://192.168.128.150:5432/thirdeye","postgres","postgres");
stmt=con.createStatement();
rs=stmt.executeQuery(query);
}catch (Exception e){ }
%>
</body>
</html>
This code is to add a row
#package com.wss;
import java.sql.*;
public class DeleteBP {
public static void main(String[] args) {
System.out.println("Deleting a Row from the Database!");
Connection con = null;
Statement stmt=null;
try{
Class.forName("org.postgresql.Driver");
con=DriverManager.getConnection("jdbc:postgresql://192.168.128.150:5432/thirdeye","postgres","postgres");
stmt=con.createStatement();
String query="Delete from businessprocessinfo where bpname=("request.getParameter('bpname')"
";int delete=stmt.executeUpdate(query);
}catch(Exception e){ }
}
}
This code is to delete a row.
Please help.
Thanks a lot in advance.
Saswati
1. Please use the hash sign "#" to insert any code in your post. The function is there for a reason.
2. Ofcourse the thing you try to do it doesn't work. You did not finishe it. From your JSP page you call servlet which is supposed to delete some data and then nothing...
What you want to do is from your JSP call servlet. Pass a request for processing, process the request, update your session bean or what ever you use store data from database. After these you call back your JSP page and show updated view.
2. Ofcourse the thing you try to do it doesn't work. You did not finishe it. From your JSP page you call servlet which is supposed to delete some data and then nothing...
What you want to do is from your JSP call servlet. Pass a request for processing, process the request, update your session bean or what ever you use store data from database. After these you call back your JSP page and show updated view.
Last edited by peter_budo; Jul 2nd, 2007 at 6:29 am.
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
•
•
•
•
Hi,
JSP Syntax (Toggle Plain Text)
String query="Delete from businessprocessinfo where bpname=("request.getParameter('bpname')":P";
Saswati
![]() |
Similar Threads
- deleting rows from a JTable (Java)
- adding and deleting node in a linked list (C++)
- Adding and deleting a column in JTable (Java)
- Deleting Rows in excel (Visual Basic 4 / 5 / 6)
Other Threads in the JSP Forum
- Previous Thread: how to deployee jsp page at myeclipse?
- Next Thread: plllllllllllz i need help
Views: 4047 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for JSP
apache array backbutton combobox comma connection csv database development directorystructure dropdownlist dynamicpagetitles eclipse frames glassfish ie8 imagetodatabse imageupload integer internet java javaee javascript jsf jsp jsppagetitles levels mvc2 mvcmodel2 mysql netbeans network parameters passing ping printinserverinsteadofclient project read redirect request.getparameter response seperated servlet servletdopost()readxml sessions software sql ssl state_saving_method stocks sun tomcat tutorial update values video web write






