hi im getting an error wen i give this syntax in order to retrieve info from my db into a txt box
<input type="text" name="tname" <%out.println(rs.getString(1));%>/>
pls help
hi im getting an error wen i give this syntax in order to retrieve info from my db into a txt box
<input type="text" name="tname" <%out.println(rs.getString(1));%>/>
pls help
try this:
<input type="text" name="tname" value='<%out.println(rs.getString(1));%>'/>
Hello i tried the code but now the problem is that when i click the delete button the record isnt getting delete please can u help thanks alot
@nazd28 please full sentence English. It part of the rules of this forum, take this as unofficial warning.
<%@ page language="java" import="java.sql.*" %>
<%
String c[]=request.getParameterValues("chbox");
Connection con = null;
Statement stmt = null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:datasrc");
stmt = con.createStatement();
for(String s:c)
{
String qy = "delete * from Table1 where id='"+s+"' ";
stmt.executeUpdate(qy);
out.println("Successfully Deleted");
}
}
catch(Exception e)
{
out.println(e.getMessage());
}
%>
After selecting the items i want to delete (using check boxes) i click the delete button. the control is transfered to another jsp page called delete.jsp(the code for that page is attached below). After clicking the button i get a page sayin null basically my control is passed to the catch. Can u pls help solve this prob
<%@ page language="java" import="java.sql.*" %> <% String c[]=request.getParameterValues("chbox"); Connection con = null; Statement stmt = null; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("jdbc:odbc:datasrc"); stmt = con.createStatement(); for(String s:c) { String qy = "delete * from Table1 where id='"+s+"' "; stmt.executeUpdate(qy); out.println("Successfully Deleted"); } } catch(Exception e) { out.println(e.getMessage()); } %>
Difficult to say what is problem as we do not know what the first page look like
PS: Database connectivity should be handled by servlet not by page it self.
Difficult to say what is problem as we do not know what the first page look like
PS: Database connectivity should be handled by servlet not by page it self.
Hi i am enclosing all the codes used by me
HTML code first page
<html>
<head runat="server">
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
<title> Delete an anniversary </title>
<script>
function chk ()
{
if(document.frm.fn.value=="")
{
element = document.getElementById("fn");
element.style.color = "red";
element.focus();
alert("in");
}
}
//to check last name
function chkln ()
{
if(document.frm.ln.value=="")
{
element = document.getElementById("ln");
element.style.color = "red";
element.focus();
alert("in");
}
}
function validate()
{
if ((document.frm.fn.value=="")&& (document.frm.ln.value==""))
{
alert("Both boxes are blank");
}
else if ((document.frm.fn.value=="")||(document.frm.ln.value==""))
{
alert("One of the boxes is blank");
}
}
</script>
</head>
<body>
<div id="wrapper">
<div id="header">
<div id="menu">
<ul>
<li><a href="birthdayandanniversarymainpage.html">Anniversary and Birthday</a></li>
<li><a href="#">Reminder</a></li>
<li><a href="#">Address book</a></li>
</ul>
</div>
<!-- end #menu -->
</div> <!-- end #header -->
<div id="logo">
<h1><a href="#">Date reminder</a></h1>
</div>
<hr />
<!-- end #logo -->
<!-- end #header-wrapper -->
<div id="page">
<div id="content">
<div class="post">
<br>
<h2 class=title> <ahref > Delete an anniversary </a> </h2>
<form name="frm" id="frm" onsubmit="validate()" action="deleteanniversary.jsp">
<h2 > <a> First name </a> </h2><input type="text" name="fn" id="fn" onblur= "chk()" ONKEYPRESS="if ((event.keyCode < 64) || (event.keyCode > 92) && (event.keyCode < 96) ||
(event.keyCode > 122) ) event.returnValue = false;"" />
<br><br>
<h2 > <a > Last name </a> </h2> <input type="text" name="ln" id="ln" onblur= "chkln()" ONKEYPRESS="if ((event.keyCode < 64) || (event.keyCode > 92) && (event.keyCode < 96) ||
(event.keyCode > 122) ) event.returnValue = false;"" />
<br />
<br>
<input type="reset" name="btreset" />
<input type="submit" name="submit" value="Submit" onclick="checkform();" />
</div>
</div>
<!-- end #content -->
<div id="sidebar">
<ul>
<li>
<h2>Birthday Facts</h2>
<br>
<a href="mainpage.html">More >> </a>
</li>
<li>
<h2>Anniversary Facts</h2>
<br>
<a href="Birthstone\starsignstonepage.html">More >> </a>
</li>
<li>
<li>
</div>
<!-- end #sidebar -->
<div style="clear: both;"> </div>
</div>
<!-- end #page -->
</div>
</form>
</body>
</html>
Deleteanniversary.jsp Code
<html>
<head runat="server">
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
<title> Delete an anniversary </title>
<script>
</script>
</head>
<body>
<form name=frm >
<div id="wrapper">
<div id="header">
<div id="menu">
<ul>
<li><a href="birthdayandanniversarymainpage.html">Anniversary and Birthday</a></li>
<li><a href="#">Reminder</a></li>
<li><a href="#">Address book</a></li>
</ul>
</div>
<!-- end #menu -->
</div> <!-- end #header -->
<div id="logo">
<h1><a href="#">Date reminder</a></h1>
</div>
<hr />
<!-- end #logo -->
<!-- end #header-wrapper -->
<div id="page">
<div id="content">
<div class="post">
<br>
<h2 class=title> <ahref > Delete an anniversary </a> </h2>
<table width="100%"border="1" >
<tr>
<th> Name</th>
<th>Anniversay date</th>
<th>Email</th>
<th>Mobileno</th>
<th> Delete </th>
</tr>
</form>
<%@ page language="java" import="java.sql.*" %>
<%int j=0;
String fname;
String lname;
lname=request.getParameter("ln");
fname=request.getParameter("fn");
Connection con =null;Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");con=DriverManager.getConnection("jdbc:odbc:datasrc");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from Table1 where fn LIKE '"+fname+"%'");
while (rs.next())
{
%>
<tr><td align="center">
<%=rs.getString(1)%> <%=rs.getString(2)%>
</td>
<td align="center">
<%=rs.getString(3)%> / <%=rs.getString(4)%> / <%=rs.getString(5)%>
</td>
<td align="center">
<%=rs.getString(6)%>
</td>
<td align="center">
<%=rs.getString(7)%>
</td>
<%String id=rs.getString(8);%>
<td ><input type="checkbox" name="chbox" value="<%=id%>"/></td>
</tr>
<%} %>
<br>
<br>
</table>
<form action="delete2.jsp">
<input type="submit" name="b1" value="Delete" >
</form>
<br>
<br>
</div>
</div>
</div>
</body>
</html>
delete.jsp Code
<%@ page language="java" import="java.sql.*" %>
<%
String c[]=request.getParameterValues("chbox");
Connection con = null;
Statement stmt = null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:datasrc");
stmt = con.createStatement();
for(String s:c)
{
String qy = "delete * from Table1 where id='"+s+"' ";
stmt.executeUpdate(qy);
out.println("Successfully Deleted");
}
}
catch(Exception e)
{
out.println(e.getMessage());
}
%>
The problem arrives in delete.jsp as the values of the checkbox arent accessible here. it goes to the catch block & displays null and even if i print String c[] it doesnt give me anything. Please can you help
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.