displaying data based on criteria from 2 tables having same type of data

displaying data based on criteria from 2 tables having same type of data

Dear Experts,

First, thanks for replying my question regarding my servlet.

My mind was very confused then. I realise that I can't use a servlet to process search criteria without having a form.

I have recently read up about DAO pattern and I think it might be able to solve my problem. Correct me if I'm wrong. Some other forums told me to use Hibernate for my problem so I'm quite lost.

Hence, I hope the experts here can give me some sample code how to write my code.

Basically, I have 2 forms already. One for tutors and the other for parents.

So, now I need a servlet (or I do not need one? ...please advise) to process a search.

The search will have following features:-

1. it enables me to enter the ID of the parents.
2. based on the ID of parents I will know what is the type of tutors they are looking for - e.g. budget, type of tutors.
3. thereafter, there will be a button to allow me to display the tutors that match the parent's requirements.

OK. I look forward to your guidance. Many thanks.

View Answers

June 8, 2010 at 5:18 PM

Hi Friend,

You can use jsp or servlet or both. We have used jsp.

Try the following code:

1)enter.jsp:

<%@page import="java.sql.*"%>
<script>
function info(sub,qua){
window.open("info.jsp?sub="+sub+"&&qua="+qua,'mywindow','width=300, height=200,toolbar=no,resizable=yes,menubar=yes');

}
</script>
<form>
Enter ID:<input type="text" name="id"><input type="submit" value="Submit" style="background-color:#49743D;font-weight:bold;color:#ffffff;">
</form>
<%String id=request.getParameter("id");
if(id!=null){
Class.forName("com.mysql.jdbc.Driver");
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql";, "root", "root");
Statement st=connection.createStatement();
ResultSet rs=st.executeQuery("SELECT * FROM parents where id='"+id+"'");
%>
<table border="1">
<tr><th>Subject</th><th>Qualification</th><th>Get Information</th></tr>
<%
while(rs.next()){
String sub=rs.getString("subjects");
String qua=rs.getString("qualification");

%>
<tr><td><%=rs.getString("subjects")%></td><td><%=rs.getString("qualification")%></td><td><input type=button value="Get" style="background-color:#49743D;font-weight:bold;color:#ffffff;" onclick='info("<%=sub%>","<%=qua%>")'></td></tr>
<%
}
%>
</table>
<%
}
%>

2)info.jsp:

<%@page import="java.sql.*"%>
<%
String sub=request.getParameter("sub");
String qua=request.getParameter("qua");
Class.forName("com.mysql.jdbc.Driver");
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql";, "root", "root");
Statement st=connection.createStatement();
ResultSet rs=st.executeQuery("SELECT * FROM memberparticulars WHERE subjects='"+sub+"' and degree='"+qua+"'");
%>
<center>
<table border="1">
<tr><th>Name</th><th>Contact</th><th>Subjects</th></tr>
<%
while(rs.next()){
%>
<tr><td><%=rs.getString("name")%></td><td><%=rs.getString("contact")%></td><td><%=rs.getString("subjects")%></td></tr>
<%
}
%>
</table>
</center>

We have created following database tables:

1)'parents'
CREATE TABLE `parents` (
`id` bigint(255) NOT NULL auto_increment,
`subjects` varchar(255) default NULL,
`qualification` varchar(255) default NULL,
PRIMARY KEY (`id`)
)
2'memberparticulars'
CREATE TABLE `memberparticulars` (
`id` bigint(255) NOT NULL auto_increment,
`name` varchar(255) default NULL,
`contact` varchar(255) default NULL,
`subjects` varchar(255) default NULL,
`degree` varchar(255) default NULL,
PRIMARY KEY (`id`)
)

Hope that it will be helpful for you.
Thanks









Related Tutorials/Questions & Answers:
displaying data based on criteria from 2 tables having same type of data - Java Beginners
displaying data based on criteria from 2 tables having same type of data ... to process search criteria without having a form. I have recently read up about.... it enables me to enter the ID of the parents. 2. based on the ID of parents I will know
same data inserted 2 times
same data inserted 2 times  thanks for reply, i know the insert command. but same data inserted 2 times.where is the problem i cannot understood
Advertisements
inserting same data to different tables in oracle
inserting same data to different tables in oracle  Hi there ...! i have to insert un,pwd, to three oracle tables, like admin, user, stud, but i want pickup these table names from a drop down list in html...is there any chance can
inserting same data to different tables in oracle
inserting same data to different tables in oracle  Hi there ...! i have to insert un,pwd, to three oracle tables, like admin, user, stud, but i want pickup these table names from a drop down list in html...is there any chance can
inserting same data to different tables in oracle
inserting same data to different tables in oracle  Hi there ...! i have to insert un,pwd, to three oracle tables, like admin, user, stud, but i want pickup these table names from a drop down list in html...is there any chance can
inserting same data to different tables in oracle
inserting same data to different tables in oracle  Hi there ...! i have to insert un,pwd, to three oracle tables, like admin, user, stud, but i want pickup these table names from a drop down list in html...is there any chance can
inserting same data to different tables in oracle
inserting same data to different tables in oracle  Hi there ...! i have to insert un,pwd, to three oracle tables, like admin, user, stud, but i want pickup these table names from a drop down list in html...is there any chance can
inserting same data to different tables in oracle
inserting same data to different tables in oracle  Hi there ...! i have to insert un,pwd, to three oracle tables, like admin, user, stud, but i want pickup these table names from a drop down list in html...is there any chance can
Displaying data from combobox on the web page
Displaying data from combobox on the web page  Sir, I have to make a project in which a data from the database is to be displayed in combo box and depending on the choice made in combo box the data pertaining to it from
Displaying data from combobox on the web page
Displaying data from combobox on the web page  Sir, I have to make a project in which a data from the database is to be displayed in combo box and depending on the choice made in combo box the data pertaining to it from
Displaying data from combobox on the web page
Displaying data from combobox on the web page  Sir, I have to make a project in which a data from the database is to be displayed in combo box and depending on the choice made in combo box the data pertaining to it from
Displaying data from combobox on the web page
Displaying data from combobox on the web page  Sir, I have to make a project in which a data from the database is to be displayed in combo box and depending on the choice made in combo box the data pertaining to it from
Displaying data from combobox on the web page
Displaying data from combobox on the web page  Sir, I have to make a project in which a data from the database is to be displayed in combo box and depending on the choice made in combo box the data pertaining to it from
Purge Data from Mysql tables
Purge Data from Mysql tables  Hi, i have to write a mysql procedure to purge data from tables. but written procedure clear entire tables data. Please give me the solution for purging data. CREATE DEFINER=`root`@`localhost
same data inserted 2 times in database
same data inserted 2 times in database  pls help me, i have table studentmaster(firstname,lastname,fathername,phone,address). i am inserting data into database 2 times the data will be inserted. forexample: firstname
displaying data
displaying data   how to display data from database on jsp using struts2
jsp programe for displaying data from database
jsp programe for displaying data from database  i am using JSP.i want..."')"); ResultSet rs = stmt.executeQuery( "SELECT * FROM data"); String id.../WebSevices/19592-retriving-data-from-sql-server-using-jsp-code-and-placing-them
jsp programe for displaying data from database
jsp programe for displaying data from database  i am using JSP.i want..."')"); ResultSet rs = stmt.executeQuery( "SELECT * FROM data"); String id.../WebSevices/19592-retriving-data-from-sql-server-using-jsp-code-and-placing-them
jsp programe for displaying data from database
jsp programe for displaying data from database  i am using JSP.i want..."')"); ResultSet rs = stmt.executeQuery( "SELECT * FROM data"); String id.../WebSevices/19592-retriving-data-from-sql-server-using-jsp-code-and-placing-them
Data Conversion from int to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from int primitive type to another data type like String, boolean and char etc
Data Conversion from String to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from String primitive type to another data type like int, boolean and char etc
Data Conversion from float to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from float primitive type to another data type like String, boolean and char etc
Data Conversion from short to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from short primitive type to another data type like String, boolean and char etc
Data Conversion from byte to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from byte primitive type to another data type like String, boolean and char etc
Data Conversion from double to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from double primitive type to another data type like String, boolean and char etc
Data Conversion from long to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from long primitive type to another data type like String, boolean and char etc
displaying data from ms excel in form.
displaying data from ms excel in form.  Hi all, I have a requirement as mentioned below: Requirement: I have stored some data in the ms excel... (for example). I need to display these data in a form. along with the actual picture
sql query to get data from two tables
sql query to get data from two tables  how can i get the data from two different tables?   Hi Friend, Please visit the following link:ADS_TO_REPLACE_1 JOIN Query Simple Query ThanksADS_TO_REPLACE_2
Data fetch from multiple SQL tables - Hibernate
that would use table classes to retrieve data from 8 or 9 tables. Any example of HQL fetching data from multiple tables would be a help. I have tried...Data fetch from multiple SQL tables   I am in the process of writing
displaying data retrieved from a database in a jsp page
displaying data retrieved from a database in a jsp page  the page should display username, emailid, telephone in addition to tthe tagline however... sql = "select billid, customerid, billdate, status from customerbills where
data (image ,audio) inserting to data base (oracle 10g) and retriving the same data from jsp
data (image ,audio) inserting to data base (oracle 10g) and retriving the same data from jsp   data (image ,audio) inserting to data base (oracle 10g) and retriving the same data from jsp with script of data base plz help me
data type
data type  which data type is used to store video file in mysql databse
how read data from doc file in same formate in jsp
how read data from doc file in same formate in jsp  how we can read and display data on jsp page, from doc file with the same formatting
take data from one table and insert same in another
take data from one table and insert same in another  I want to know when a new field update in table and the same data has to update in another table
Conversion from string data type into different data types.
Conversion from string data type into different data types.  string str="World id Beutifull"; char chr[20]; char* chrctr ; Qustion is -How to store the 'str' value in 'chr' and 'chrctr'? int abc; sprintf(abc ,"%s",str
Selecting particular data from multiple tables at database and perfoming calculations
Selecting particular data from multiple tables at database and perfoming... to maintain the details based on month (because the other modules in this project needs the output based on month) .. I have created 12 tables with table name
how to retrieve data from multiple tables in jsp using javabeans
how to retrieve data from multiple tables in jsp using javabeans   ... for retrieving data fromm two tables : first table having fields: bookid,name,phno second table having field: seat-id But the data is not retrieved:why so
how to retrieve data from multiple tables in jsp using javabeans
how to retrieve data from multiple tables in jsp using javabeans   ... for retrieving data fromm two tables : first table having fields: bookid,name,phno second table having field: seat-id But the data is not retrieved:why so
how to retrieve data from multiple tables in jsp using javabeans
how to retrieve data from multiple tables in jsp using javabeans   ... for retrieving data fromm two tables : first table having fields: bookid,name,phno second table having field: seat-id But the data is not retrieved:why so
xml displaying a drives data.....
xml displaying a drives data.....  Hi all, I need a solution for displaying content of a drive(Ex: c , d , e ) in the browser using the XML..., You can't access the your drive data from browser. But you can create some
Get date data type from table
GET DATE DATA TYPE FROM TABLE In this example , we will get "Date" data type from a table of "Mysql" database and it also display... data = rs.getString(2);                 System.out.println(name +"\t"+data
Is big data and data science same?
Is big data and data science same?  Hi, I am beginner in Data...: Is big data and data science same? Try to provide me good examples or tutorials links so that I can learn the topic "Is big data and data science same?"
Is Data Analyst same as data scientist?
Is Data Analyst same as data scientist?  Hi, I am beginner in Data...: Is Data Analyst same as data scientist? Try to provide me good examples or tutorials links so that I can learn the topic "Is Data Analyst same as data
data type
data type  what are the date types in the java and vb.net? what is the difference between java and vb.net?   Hi Friend, java data types... vb.net data types are: Byte SByte Short UShort Integer UInteger Long ULong
How to Generate XML files from the data in DB tables?
How to Generate XML files from the data in DB tables?  HI Experts, I have a doubt. I have a table say Pest. My task is to generate XML file...(); ResultSet rs=st.executeQuery("select * from employee where id=1
Is data science and analytics same?
Is data science and analytics same?  Hi, I am beginner in Data...: Is data science and analytics same? Try to provide me good examples or tutorials links so that I can learn the topic "Is data science and analytics same
Data displaying with limited records in jsp
Data displaying with limited records in jsp  How to display table with limited 10 records , after clicking next button another 10 records from database upto last record please help me
displaying data for a single column from Mysql database in the list box in php form
displaying data for a single column from Mysql database in the list box in php form  I have a form in php.want to display data from a single column...; $data = @mysql_query("select * from names"); echo "Select a Name: n"; echo "<
alter data type
alter data type  alter data type of subName column for subject table to varchar(40
How to Retrieve Excel data into mysql using type 2 JDBC-ODBC driver
How to Retrieve Excel data into mysql using type 2 JDBC-ODBC driver  .... so, can any one help me without creating DNS we should retrieve data from excel... type 1 driver and i have done successfully.but disadvantage is when i create

Ads