LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-12-2005, 07:22 AM   #1
anirudh
Member
 
Registered: Aug 2004
Location: bangalore india
Posts: 50

Rep: Reputation: 15
Exclamation urgent help on JSP


Hi i am in urgent need of help to have a jsp
that retrieves information from a database table and shows it ,
also it should have checkboxes to select records and then have edit option to edit information in that record. or delete the record or update. can
some one guide me with help of a code . or it would be very helpful if some one could pass me a reusable code that does the same .
i am in urgent need to do this , plz help
 
Old 08-12-2005, 07:29 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
please do not mark threads as "urgent"... it is not urgent for any of the momebers of LQ.org who kindly donate their time to help others.

As for your request, you've provided so little information about your situation i don't see how anyone could really help anyway. If you don't undestand a particular function call or syntax error, then we can help we can't help you make "something with checkboxes and updates on it"...
 
Old 08-12-2005, 09:24 AM   #3
oblivious69
Member
 
Registered: May 2005
Distribution: debian
Posts: 79

Rep: Reputation: 15
why not post what you have and we'll see what we can do.
 
Old 08-12-2005, 11:34 AM   #4
anirudh
Member
 
Registered: Aug 2004
Location: bangalore india
Posts: 50

Original Poster
Rep: Reputation: 15
hey guys i have to do multiple delete on the table being populated depending on the checkbox

i have tried some simple jsp stuff as shown below

could you help me in fixing the problems

<%@ page import='java.sql.*' %>
<%@ page import='java.io.*' %>

<HTML>
<HEAD>

<SCRIPT LANGUAGE="JavaScript">



function Delete(Array checkedrows)
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn=DriverManager.getConnection("jdbcracle:thin:@152.69.213.16:1521rcl","scott","welcome1" );
Statement stmt = conn.createStatement();
ResultSet rs=stmt.executeUpdate("delete from emp where empno in ("checkedrows");");
}

</SCRIPT>
</HEAD>
<BODY>
<TABLE border="1">
<TR>
<TD>

<TR>

<%
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn=DriverManager.getConnection("jdbcracle:thin:@152.69.213.16:1521rcl","scott","welcome1" );
Statement stmt = conn.createStatement();
ResultSet rs=stmt.executeQuery("SELECT * FROM EMP");
Array checkedrows;
%>
<TH></TH>
<TH>EmpID</TH>
<TH>EmpName</TH>
<TH>Job</TH>
<TH>Salary</TH>
<form name="TABLE" method="GET" onSubmit="return false">
<%
while(rs.next()){
%>
<TR>
<TD><input type="CHECKBOX" name="Checkrows" value="<%=rs.getInt(1)%>"</TD>
<TD><%=rs.getInt(1)%></TD>
<TD><%=rs.getString(2)%></TD>
<TD><%=rs.getString(3)%></TD>
<TD><%=rs.getInt(6)%></TD>

>>

</TR>
</TD>
<%
}
%>

<%
if (Checkrows.isChecked())
{
checkedrows[].add(Checkrows);
}
%>

<TD></TD>
<TD></TD>
<TD><input type="Submit" name="Delete" value="Delete" onclick="Delete(checkedrows);"></TD>
</FORM>
</TR>

</TD>
<TD>
</TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>

Thanks
 
Old 08-12-2005, 11:27 PM   #5
oblivious69
Member
 
Registered: May 2005
Distribution: debian
Posts: 79

Rep: Reputation: 15
the following code should be inside some javascript tags:

Code:
<%
if (Checkrows.isChecked())
{
checkedrows[].add(Checkrows);
}
%>
Plus I don't think the quotes are right for the following code:
Code:
ResultSet rs=stmt.executeUpdate("delete from emp where empno in ("checkedrows");");
Also, I don't think all the values from checkedrows will be displayed that way.

In sql, to do the delete, you would probably need to do something like

Code:
delete from emp where empno in (23, 34, 45)
Also, most of the stuff in your javascript should be java code. I think you are mixing up javascript and java.

Last edited by oblivious69; 08-12-2005 at 11:30 PM.
 
Old 08-16-2005, 06:45 AM   #6
anirudh
Member
 
Registered: Aug 2004
Location: bangalore india
Posts: 50

Original Poster
Rep: Reputation: 15
hey thanks a lot to correct my errors ;
i have fixed my problems and here is the code i have come up with

<%@ page import='java.sql.*'%>
<%@ page import='java.io.*' %>

<HTML>
<HEAD>

</HEAD>
<BODY>
<TABLE border="1">
<TR>
<TD>

<TR>

<%
Statement stmt = null;
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn=DriverManager.getConnection("jdbcracle:thin:@152.69.213.16:1521rcl","scott","welcome1" );
stmt = conn.createStatement();

String[] checked = request.getParameterValues("Checkrows");
if (checked != null && checked.length != 0)
{
for ( int i = 0; i < checked.length; i++ )
{
String temp = "delete from emp where empno = " + checked[i];
out.println(temp);
stmt.executeUpdate("delete from emp where empno = " + checked[i]);
}
}
/*
if (Checkrows.isChecked())
{
checkedrows[].add(Checkrows);
}
*/
conn.close();
}
catch(Exception e)
{
e.printStackTrace();
}

ResultSet rs=stmt.executeQuery("SELECT * FROM EMP");
Array checkedrows;
%>


<TH></TH>
<TH>EmpID</TH>
<TH>EmpName</TH>
<TH>Job</TH>
<TH>Salary</TH>
<form name="TABLE" method="GET" action="checkbox.jsp">
<%
while(rs.next()){
%>
<TR>
<TD><input type="CHECKBOX" name="Checkrows" value="<%=rs.getInt(1)%>"</TD>
<TD><%=rs.getInt(1)%></TD>
<TD><%=rs.getString(2)%></TD>
<TD><%=rs.getString(3)%></TD>
<TD><%=rs.getInt(6)%></TD>

</TR>
</TD>
<%
}
%>
<input type="submit" value="Delete"/>




<TD></TD>
<TD></TD>
<TD></TD>
</FORM>
</TR>

</TD>
<TD>
</TD>
</TR>
</TABLE>
<form>
</form>


</BODY>
</HTML>
 
Old 08-16-2005, 06:02 PM   #7
anirudh
Member
 
Registered: Aug 2004
Location: bangalore india
Posts: 50

Original Poster
Rep: Reputation: 15
i have modified the code to incorporate insert option into it so here


<%@ page import='java.sql.*'%>
<%@ page import='java.io.*' %>

<HTML>
<HEAD>

</HEAD>

<%
Statement stmt_1 = null;
Statement stmt_2=null;
Connection conn = null;

try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
conn=DriverManager.getConnection("jdbcracle:thin:@152.69.213.182:1521:anirudh","scott","tiger" );
stmt_1 = conn.createStatement();
String test = request.getParameter("empno");
if (test!= null)
{




stmt_1.executeUpdate("INSERT INTO EMP (empno,ename,job,sal) VALUES (" + request.getParameter("empno") + ",'" +
request.getParameter("ename1") + "','" +
request.getParameter("job1") + "'," +
request.getParameter("salary1") + ")");
/*String temp1= "INSERT INTO EMP(empno, ename,job,sal) VALUES (" + request.getParameter("empno") + ",'" +
request.getParameter("ename1") + "','" +
request.getParameter("job1") + "'," +
request.getParameter("salary1")+ ")";

out.println(temp1);
out.println("ename "+ request.getParameter("TABLE1.ename"));
*/
}




String[] checked = request.getParameterValues("Checkrows");
if (checked != null && checked.length != 0)
{
for ( int i = 0; i < checked.length; i++ )
{
String temp = "delete from emp where empno = " + checked[i];
out.println(temp);
stmt_1.executeUpdate("delete from emp where empno = " + checked[i]);
}
}




/*
if (Checkrows.isChecked())
{
checkedrows[].add(Checkrows);
}
*/

}
catch(Exception e)
{
e.printStackTrace();
}
stmt_2 = conn.createStatement();
ResultSet rs=stmt_2.executeQuery("SELECT * FROM EMP");
Array checkedrows;
%>

<BODY>
<TABLE border="1" width="649" cellspacing="1" cellpadding="2">
<TR>
<TH></TH>
<TH>EmpID</TH>
<TH>EmpName</TH>
<TH>Job</TH>
<TH>Salary</TH>
</tr>
<form name="TABLE" method="GET" action="checkbox.jsp">
<%
while(rs.next()){
%>
<TR>
<TD><input type="CHECKBOX" name="Checkrows" value="<%=rs.getInt(1)%>"></TD>
<TD><div align="center"><%=rs.getInt(1)%></div></TD>
<TD><div align="center"><%=rs.getString(2)%></div></TD>
<TD><div align="center"><%=rs.getString(3)%></div></TD>
<TD><div align="center"><%=rs.getInt(6)%></div></TD>
</TR>
<%
}
%>
<tr>
<td colspan=5 align="center"><input type="submit" value="Delete"/></td>
</FORM>
</TR>
<tr>&nbsp;</tr>
<tr>&nbsp;</tr>


<form name="TABLE1" method="GET" action="checkbox.jsp">
<tr>
<td>&nbsp;</td>
<td><div align="left">Employee id </div></td>
<td><input type="text" name="empno"/></td>
<td>Employee Name </td>
<td><input type="text" name="ename1"/></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><div align="left">Job </div></td>
<td><input type="text" name="job1"/> </td>
<td>Salary </td> <td><input type="text" name="salary1"/></td>
</tr>
<tr>
<td colspan=5 align="center">
<input type="submit" value="insert">
</td>
</tr></form>
</TABLE>
</BODY>
</HTML>
 
Old 08-16-2005, 06:03 PM   #8
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
what do you expect people to be replying with??
 
Old 08-17-2005, 05:54 PM   #9
anirudh
Member
 
Registered: Aug 2004
Location: bangalore india
Posts: 50

Original Poster
Rep: Reputation: 15
i dont want anyone to reply ,but thought people looking at the thread might provide me with a better way to do this or it might help others who want to do somethin like this
what else are these threads for anyways
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
boot sector and lilo collapse !!!!! URGENT URGENT URGEN !!!!! frelihm Linux - Software 21 12-02-2009 11:21 AM
Urgent Question Regarding Urgent Questions! Need Help Now! Crashed_Again LQ Suggestions & Feedback 11 10-17-2007 09:07 PM
Urgent Urgent !!!! Mozilla Keeps All Your Deleted Emails !!!! odin123 Linux - Software 2 01-31-2004 03:22 AM
VB to JSP jayakrishnan Linux - General 3 05-08-2002 01:28 AM
jsp deepak Programming 0 04-18-2001 10:49 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration