Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Search data from database
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Ragini Shukla
Search data from database
2 Answer(s)      6 years and 2 months ago
Posted in : Java Beginners



Advertisement
View Answers

August 11, 2008 at 5:32 PM


hai frnd...i'm prashob not deepak....
i think u r working with jsp....
then on clicking this search and delete(both shpould be submit type) forward it to a new jsp page,
then

//this is initialization
<%@ page import="java.sql.*" %>
<%! Connection con;
ResultSet rst;
Statement st;
String url="jdbc:db2://url/db:"; //this is the url to ur database

%>
//this is class loading.here i used type4 driver for ibm db2.change according to ur db.

<%
try
{
Class.forName("com.ibm.db2.jcc.DB2Driver");
con=DriverManager.getConnection(url,"user","pwd");
System.out.println("After Establishing connection");
}
catch(ClassNotFoundException e)
{
System.out.println("ERROR!1: "+e);

}
%>


//create table

<table>
<tr><td>NAME</td><td>last name</td></tr> //this is table header


//i assume ur table name as "table" and the column name as name.and this table's first column as name and second column as last name

<%
try
{

st=con.createStatement();
rst=st.executeQuery("select * from table where name='"+request.getAttribute("name")+"' order by 1");
System.out.println("After select");
while(rst.next())
{
System.out.println("inside while");%>
//the following statement is for displaying the names.
<tr>
<td> <%= rst.getString(1) %></td>
<td> <%= rst.getString(2) %></td>
</tr>


<%} }

System.out.println("After reading values");

}

catch(Exception e)
{
System.out.println("ERROR!!2 :"+e);

}


%>


</table>

this is the case for displaying names on a page..
if u want to delete ,then find out which submit button is pressed in the previous page,
then according to that,
use the sql command as delete * from table where name "the value passed from the previous page..
i mean request.getParameter("name");

hope it would help u....
for further needs ...get me at prashobvee@gmail.com

thanks and regards
prashu...






August 11, 2008 at 5:45 PM



hai,
the above code assumes u have only two columns in the table.....if u have many columns in the table,i mean u have many datafields to be displayed add in the while loop and html table definition also....
this displayes all the users with same name.....because there may be many persons having same ..u didnt tell this name is a unique value..



thanks and reg..
prashu


Related Tutorials/Questions & Answers:
Search data from database - Java Beginners
Search data from database  Hi Deepak, This is not correct code... to user name. (means search all field from database and display using... with two button search and delete. 2:- User input name(with alphabetical
how to display data from database according to entered value in search field
how to display data from database according to entered value in search...(); System.out.println("Disconnected from database"); } catch (Exception e...; <input type="submit" name="submit" value="Search">
Advertisements
search from database
search from database  DBUtil util = new DBUtil(); try { JOptionPane.showMessageDialog(null, "Connection Opened!"); Connection con...); }   i want to retrieve values from database and display them in my
search functionality using jsp from database
search functionality using jsp from database  search functionality using jsp from database
selecting data from database
selecting data from database  how to select data from database using Dao in struts   Hi, You have to load the data from database using hibernate and send the data in a Java file object to jsp page. Please read at http
retrive data from database
retrive data from database   hi.. i made a application form. it's have attribute s.no,name,roll no and i enter a few records. now i want to view all record not in database access sheet i want to view it at any another
retrive data from database?
retrive data from database?  hellow i have a database sheet name as db1. it's contain sixty(60) sn,name ,rollno(primary key),father's name etc... from db1 and enter value in text box according there name,rollno and save
how to retrieve data from database ?????/
how to retrieve data from database ?????/  how to retrieve data from database
how to retrieve data from database ?????/
how to retrieve data from database ?????/  how to retrieve data from database
how to retrieve data from database ?????/
how to retrieve data from database ?????/  how to retrieve data from database
how to retrieve data from database ?????/
how to retrieve data from database ?????/  how to retrieve data from database
fetch data from database in javascript
fetch data from database in javascript   How to fetch data from database in JavaScript when it is a leap year
how to retrieve data from database
how to retrieve data from database  unable to retrieve data from database using mySQL by using jsp sessions and beans for editing
retrieve data from mysql database
retrieve data from mysql database  hi am not familiar in php.....even... selected value on combobox which is to be retrieve the relevant data from mysql database using php.... below my code is that.. <html> <head>
How to search the table name in MS SQL Database 2005 from application
How to search the table name in MS SQL Database 2005 from application  How to search the table name in MS SQL Database 2005 from application from our helpdesk application? application might be in html
delete data from database - SQL
delete data from database  HOw to delete specific data from table> I want to delete one record from database. Thnx  Hi friend, -------------------------------------------- Visit for more information
To retrive data from database - Struts
To retrive data from database  How to get values ,when i select a select box in jsp and has to get values in textbox automatically from database? eg... come to jsp page automatically from database
Problem in accessing data from Database
Problem in accessing data from Database  hi..... i'm making a project on servlet and jsp with ms access 2007 at the backend. One field in my database is text and all others are of currency data type. If i enter 0 or null value
retrieve data from database with hyperlink
retrieve data from database with hyperlink  sir....i have one table called 'name' having two values i have to retrieve those data with a hyperlink and show in browser and if we click hyperlink its shows his sub categories....how
retreive integer data from database
retreive integer data from database  i made a table named result...=lalit&database=mydb"); String url="select marks from student where rollno... and two buttons "ok" and "cancel" i want to take input from textfield
Getting Textbox data from database
data from database and display it on the textboxes. <%@page language="java...Getting Textbox data from database  When i m trying to get data in textbox as readonly from database i m getting following error.and my code is shown
Getting Textbox data from database
;Here is a jsp code that retrieves data from database and display...Getting Textbox data from database  When i m trying to get data in textbox as readonly from database i m getting following error.and my code is shown
Data retrieve from mysql database
Data retrieve from mysql database  Hi sir, please give some example of jsp code for retrieving mysql database values in multiple dropdown list... from the dropdown, related data will get displayed on the textboxes. Here we have
GWT -- retrive the data from Database
GWT -- retrive the data from Database  the user can create an event. In the create page, we have three buttons. Save as draft, preview and save... button, you have to create a dynamic jsp which should read the contents from
how to display data from database in jsp
how to display data from database in jsp  how to display data from database in jsp
how to use bean to retrieve data from database
how to use bean to retrieve data from database  how to use bean to retrieve data from database   poda sendru
Retrieval data from database against timer
Retrieval data from database against timer  Please send me a sample timer code which retrieve data from the database against timer in JSP
data insertion from xml file to database table
data insertion from xml file to database table  Hi all, I have data in the XML file. I need to insert it into table in the database using servlet. so please reply me . ThankYou
to fetch data from ms word and storing into database
to fetch data from ms word and storing into database  i want to know how to fetch datafields from ms word and storing into database??? please answer soon .its urgent
display data from database on selecting option of dropdownlist
display data from database on selecting option of dropdownlist   Sir I want to display data from database by just selecting option of dropdown list... is that to display image from database in a grid format or in a fixed column and row
display data from database on selecting option of dropdownlist
display data from database on selecting option of dropdownlist   Sir I want to display data from database by just selecting option of dropdown list... is that to display image from database in a grid format or in a fixed column and row
Advertisements
 

 

 

DMCA.com