Adding a deleting rows

Reply

Join Date: Jun 2007
Posts: 15
Reputation: saswati_mishra is an unknown quantity at this point 
Solved Threads: 0
saswati_mishra saswati_mishra is offline Offline
Newbie Poster

Adding a deleting rows

 
0
  #1
Jul 2nd, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,257
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 493
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Adding a deleting rows

 
0
  #2
Jul 2nd, 2007
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.
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
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 686
Reputation: sillyboy is on a distinguished road 
Solved Threads: 61
sillyboy's Avatar
sillyboy sillyboy is offline Offline
Practically a Master Poster

Re: Adding a deleting rows

 
0
  #3
Jul 6th, 2007
Originally Posted by saswati_mishra View Post
Hi,

  1. String query="Delete from businessprocessinfo where bpname=("request.getParameter('bpname')":P";

Saswati
Have you tried this in SQL, because you are trying to access a variable within a string without catenation (spelling?).
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 4047 | Replies: 2
Thread Tools Search this Thread



Tag cloud for JSP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC