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



Home Answers Viewqa Java-Beginners displaying data based on criteria from 2 tables having same type of data
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Karen
displaying data based on criteria from 2 tables having same type of data
1 Answer(s)      4 years and 7 months ago
Posted in : Java Beginners


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.


Advertisement
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
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
displaying data
displaying data   how to display data from database on jsp using struts2
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 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
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
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: JOIN Query Simple Query Thanks
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 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
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
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 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 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
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 type
data type  which data type is used to store video file in mysql databse
 

 

 

DMCA.com